A large number of questions is the most suitable for Java. Java. math. BigDecimal; java. math. BigInteger; provides many practical methods to help you process big data.
Hangdian's big data questions are summarized as follows:
1002,104 2, 2054
HDOJ1047 Integer InquiryInteger Inquiry
import java.util.Scanner;import java.math.BigInteger;public class Main {/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stubScanner scanner=new Scanner(System.in); int n; BigInteger m,sum; n=scanner.nextInt(); for(int i=1;i<=n;i++){ sum=BigInteger.ZERO; while(scanner.hasNextBigInteger()){ m=scanner.nextBigInteger(); if(m.equals(BigInteger.ZERO)) //if(m.intValue()==0) break; sum=sum.add(m); } System.out.println(sum); if(i<n) System.out.println(); } }}
HDOJ1063 Exponentiation
import java.util.Scanner;import java.math.*;public class Main {/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stubScanner scanner=new Scanner(System.in);//float a;int n;BigDecimal a,r;while(scanner.hasNextFloat()){a=scanner.nextBigDecimal();n=scanner.nextInt();r=BigDecimal.ONE;for(int i=1;i<=n;i++)r=r.multiply(a);String s=r.stripTrailingZeros().toPlainString();if(s.charAt(0)=='0')System.out.println(s.substring(1));elseSystem.out.println(s);}}}
HDOJ1297 Children's Queue
import java.util.Scanner;import java.math.BigInteger;public class Main {/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stubScanner scanner=new Scanner(System.in);int n;BigInteger []r=new BigInteger[1005];r[1]=BigInteger.valueOf(1);r[2]=BigInteger.valueOf(2);r[3]=BigInteger.valueOf(4);r[4]=BigInteger.valueOf(7);for(int i=5;i<=1000;i++)r[i]=r[i-1].add(r[i-2]).add(r[i-4]);while(scanner.hasNextInt()){n=scanner.nextInt();System.out.println(r[n]);}}}
HDOJ1316 How Many Fibs?
import java.util.Scanner;import java.math.BigInteger;public class Main{/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stubScanner scanner=new Scanner(System.in);int count;BigInteger a,b;BigInteger []r=new BigInteger[1005];r[1]=BigInteger.valueOf(1);r[2]=BigInteger.valueOf(2);for(int i=3;i<=1000;i++)r[i]=r[i-1].add(r[i-2]);while(scanner.hasNextBigInteger()){a=scanner.nextBigInteger();b=scanner.nextBigInteger();if(a.equals(BigInteger.valueOf(0))&&b.equals(BigInteger.valueOf(0)))return;count=0;for(int j=1;j<=1000;j++){if(r[j].compareTo(a)>=0&&r[j].compareTo(b)<=0)count++;}System.out.println(count);}}}
HDOJ1715
import java.util.Scanner;import java.math.BigInteger;public class Main{/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stubScanner scanner=new Scanner(System.in);BigInteger []a=new BigInteger[1005];a[1]=a[2]=BigInteger.valueOf(1);for(int j=3;j<=1000;j++){a[j]=a[j-1].add(a[j-2]);}int n,m;n=scanner.nextInt();for(int i=1;i<=n;i++){m=scanner.nextInt();System.out.println(a[m]);}}}
HDOJ1753 Daming A + B
import java.util.Scanner;import java.math.*;public class Main {/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stubScanner scanner=new Scanner(System.in);BigDecimal a,b;while(scanner.hasNextBigDecimal()){a=scanner.nextBigDecimal();b=scanner.nextBigDecimal();a=a.add(b);String s=a.stripTrailingZeros().toPlainString();System.out.println(s);}}}