hdu 1063 n^m舍去多余的0
1 import java.math.BigDecimal; 2 import java.math.BigInteger; 3 import java.util.Scanner; 4 5 6 public class Main { 7 public static void main(String[] args) { 8 BigDecimal n,ans; 9 10 Scanner sc=new Scanner(System.in); 11 while(sc.hasNextBigDecimal()) 12 { 13 int m; 14 n=sc.nextBigDecimal(); 15 m=sc.nextInt(); 16 ans=new BigDecimal("1"); 17 for(int i=0;i<m;i++) 18 ans=ans.multiply(n); 19 ans=ans.stripTrailingZeros(); 20 String str=ans.toPlainString(); 21 if(str.startsWith("0.")) 22 str=str.substring(1); //以从1开始的子串为新串
23 System.out.println(str); 24 25 26 27 } 28 29 30 31 } 32 33 }
hdu 1047
1 import java.math.BigInteger; 2 import java.util.Scanner; 3 4 5 public class Main { 6 public static void main(String[] args) { 7 BigInteger ans,n,one,i,zero,m; 8 Scanner sc=new Scanner(System.in); 9 n=sc.nextBigInteger(); 10 zero=new BigInteger("0"); 11 12 one=new BigInteger("1"); 13 while(n.compareTo(zero)>0) 14 { 15 ans=new BigInteger("0"); 16 while(true) 17 { 18 m=sc.nextBigInteger(); 19 if(m.compareTo(zero)==0) 20 break; 21 ans=ans.add(m); 22 } 23 System.out.println(ans); 24 n=n.subtract(one); 25 if(n.compareTo(zero)!=0) 26 System.out.println(""); 27 28 } 29 30 31 } 32 33 }
hdu 1042
1 //package 大数; 2 3 import java.math.BigInteger; 4 import java.util.Scanner; 5 6 7 public class Main { 8 9 public static void main(String[] args) { 10 BigInteger ans,i,n,one; 11 Scanner sc=new Scanner(System.in); 12 while(sc.hasNextBigInteger()) 13 { 14 n=sc.nextBigInteger(); 15 one=new BigInteger("1"); 16 ans=new BigInteger("1"); 17 i=new BigInteger("1"); 18 19 while(i.compareTo(n)<=0) 20 { 21 22 23 ans=ans.multiply(i); 24 25 i=i.add(one); 26 27 28 } 29 System.out.println(ans); 30 31 } 32 } 33 34 }
原文:http://www.cnblogs.com/assult/p/3848467.html