【Java】Java划水练习
bzoj1000 A+B Problem
Scanner sc=new Scanner(new BufferedInputStream(System.in)); 声明读入器
nextInt 读入整数
System.out.println 带换行输出
import java.util.*; import java.io.*; public class Main{ public static void main(String[] argc){ Scanner sc = new Scanner (new BufferedInputStream(System.in)); int a=sc.nextInt(),b=sc.nextInt(); System.out.println(a+b); sc.close(); } }
poj1503 Integer Inquiry
BigInteger.ZERO 大整数常量零
equals 相等
add 加
import java.util.*; import java.io.*; import java.math.*; public class Main{ public static void main(String[] argc){ Scanner sc = new Scanner (new BufferedInputStream(System.in)); BigInteger sum=BigInteger.ZERO; while(true){ BigInteger x=sc.nextBigInteger(); if(x.equals(BigInteger.ZERO)){ break; } sum=sum.add(x); } System.out.println(sum); sc.close(); } }
poj1001 求高精度幂
stripTrailingZeros 清除不影响大小的零
toPlainString 以朴素的方式(而非科学计数法或工程计数法)将BigDecimal转换成String
hasNext 判断是否读入完成
next 读入字符串,直到空格为止
nextLine 读入一整行字符串
public String substring(int beginIndex) 返回该字符串从beginIndex开始到结尾的子字符串;
public String substring(int beginIndex,int endIndex) 返回该字符串从beginIndex开始到endsIndex结尾的子字符串
import java.util.*; import java.io.*; import java.math.*; public class Main { public static void main(String[] argc){ Scanner sc=new Scanner(new BufferedInputStream(System.in)); while(sc.hasNext()){ String s=sc.next(); int n=sc.nextInt(); BigDecimal x=new BigDecimal(s); s=x.pow(n).stripTrailingZeros().toPlainString(); if(s.charAt(0)=='0'){ s=s.substring(1); } System.out.println(s); } sc.close(); } }
bzoj1876 [SDOI2009]SuperGCD
gcd 求两个大整数的gcd
import java.util.*; import java.io.*; import java.math.*; public class Main { public static void main(String[] argc){ Scanner sc=new Scanner(new BufferedInputStream(System.in)); BigInteger a=sc.nextBigInteger(); BigInteger b=sc.nextBigInteger(); System.out.println(a.gcd(b)); sc.close(); } }
——The Solution By AutSky_JadeK From UESTC
转载请注明出处:http://www.cnblogs.com/autsky-jadek/