首页 > 代码库 > JAVA的acm用法

JAVA的acm用法

<span style="font-family: Arial, Helvetica, sans-serif;"> </span>
import java.math.*;
import java.util.*;
public class Main {
		public static void main(String[] args) {
				Scanner cin = new Scanner(System.in);
				BigInteger c = new BigInteger("0");
				while(cin.hasNext()){
					BigInteger a = cin.nextBigInteger();
					BigInteger b = cin.nextBigInteger();
					if((a.compareTo(c)==0) && (b.compareTo(c)==0))
						break;
					int ok = a.compareTo(b);
					if(ok==0)
						System.out.println("a==b");
					else if(ok==-1)
						System.out.println("a<b");
					else
						System.out.println("a>b");
				}
				
		}
}
        

大数比较大小。

 
import java.math.*;
import java.util.*;
public class Main {
		public static void main(String[] args) {
				Scanner cin = new Scanner(System.in);
				while(cin.hasNext()){
					int a = cin.nextInt();
					BigInteger ans = new BigInteger("1");
					for(int i=1;i<=a;i++)
					{
						BigInteger tmp = BigInteger.valueOf(i);
						ans = ans.multiply(tmp);
					}
					System.out.println(ans);
				}
		}
}
        

nyoj 155 大数次方

import java.math.*;
import java.util.*;
public class Main {
		public static void main(String[] args) {
				Scanner cin = new Scanner(System.in);
				while(cin.hasNext()){
					BigDecimal a = cin.nextBigDecimal();
					BigDecimal ans = new BigDecimal("1.0");
					int num = cin.nextInt();
					ans = a.pow(num);
//					for(int i=1;i<=num;i++)
//					{
//						ans = ans.multiply(a);
//					}
					String str = ans.stripTrailingZeros().toPlainString();
					if(str.startsWith("0")) //取掉前导0
						str = str.substring(1);
					System.out.println(str);
				}
		}
}



JAVA的acm用法