Hdu1002
Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1002
Code:
import java.math.BigInteger;import java.util.Scanner;import java.io.*;public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); while(cin.hasNextInt()){ BigInteger a,b,c; int t,i; t=cin.nextInt(); i=1; while(i<=t){ a=cin.nextBigInteger(); b=cin.nextBigInteger(); c=a.add(b); System.out.println("Case "+i+":"); System.out.println(a+" + "+b+" = "+c); if(i<t)System.out.println(""); i++; } } }}
Hdu1042
Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1042
Code:
import java.math.BigInteger;import java.util.Scanner;import java.io.*;public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); BigInteger a,i,t; BigInteger one = new BigInteger("1"); while(cin.hasNextBigInteger()){ t=cin.nextBigInteger(); i=new BigInteger("1"); a=new BigInteger("1"); int cmp=i.compareTo(t); while(cmp<=0){ a=a.multiply(i); i=i.add(one); cmp=i.compareTo(t); } System.out.println(a); } }}
Hdu1047
Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1047
Code:
import java.math.BigInteger;import java.util.Scanner;import java.io.*;public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); BigInteger a,b; int i,t; BigInteger zero = new BigInteger("0"); while(cin.hasNextInt()){ t=cin.nextInt(); for(i=1;i<=t;i++){ boolean flag=true; b=zero; while(flag){ a=cin.nextBigInteger(); if(a.compareTo(zero)==0)flag=false; b=b.add(a); } System.out.println(b); if(i<t)System.out.println(""); } } }}
Hdu1063
Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1063
Note that the simplest form is to remove the following 0 and the decimal point before the decimal point smaller than 1.
Code:
import java.math.BigDecimal;import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); int n,i; BigDecimal r,a; BigDecimal one = new BigDecimal("1"); while(cin.hasNextBigDecimal()){ r=cin.nextBigDecimal(); n=cin.nextInt(); a=one; for(i=1;i<=n;i++) a=a.multiply(r); a=a.stripTrailingZeros(); String str=a.toPlainString(); if(str.startsWith("0.")) str=str.substring(1); System.out.println(str); } }}
Hdu1316
Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1316
Code:
import java.math.BigInteger;import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); int i,j; BigInteger a,b; BigInteger f[] = new BigInteger[501]; BigInteger zero = new BigInteger("0"); f[1]=new BigInteger("1"); f[2]=new BigInteger("2"); for(i=3;i<=500;i++) f[i]=f[i-1].add(f[i-2]); while(cin.hasNextBigInteger()){ a=cin.nextBigInteger(); b=cin.nextBigInteger(); if(a.compareTo(zero)==0 && b.compareTo(zero)==0)break; for(j=0,i=1;i<=500;i++){ if(a.compareTo(f[i])<=0 && b.compareTo(f[i])>=0)j++; if(b.compareTo(f[i])<0)break; } System.out.println(j); } }}
Hdu1715
Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1715
Code:
import java.math.BigInteger;import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); int i,j,t; BigInteger f[] = new BigInteger[1001]; f[1]=new BigInteger("1"); f[2]=new BigInteger("1"); for(i=3;i<=1000;i++) f[i]=f[i-1].add(f[i-2]); while(cin.hasNextInt()){ t=cin.nextInt(); for(i=1;i<=t;i++){ j=cin.nextInt(); System.out.println(f[j]); } } }}
Hdu1753
Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1753
Code:
Similarly, the simplest decimal form should be removed from the integer part of the number smaller than 1.
import java.math.BigDecimal;import java.math.BigInteger;import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); BigDecimal a,b; BigInteger zero = new BigInteger("0"); while(cin.hasNextBigDecimal()){ a=cin.nextBigDecimal(); b=cin.nextBigDecimal(); a=a.add(b); a=a.stripTrailingZeros(); String str=a.toPlainString(); if(str.startsWith("0.")) str=str.substring(1); System.out.println(str); } }}