java大数a+b

hdu1000

import java.util.Scanner;//输入
import java.math.BigInteger;//大整数类
import java.math.BigDecimal;//大浮点数类
public class Main {
    public static void main(String[] args) {
        Scanner s=new Scanner(System.in);
        BigInteger[] a = new BigInteger[1000];
        while(s.hasNext())
        {
            a[0]=s.nextBigInteger();
            a[1]=s.nextBigInteger();
            a[2]=s.nextBigInteger();
            System.out.println(a[0].add(a[1].add(a[2])));
        }
    }
}

hdu1250

import java.util.Scanner;//输入
import java.math.BigInteger;//大整数类
import java.math.BigDecimal;//大浮点数类
public class Main {
    public static void main(String[] args) {
        Scanner s=new Scanner(System.in);
        BigInteger[] a = new BigInteger[10010];
        a[1] = new BigInteger("1");
        a[2] = new BigInteger("1");
        a[3] = new BigInteger("1");
        a[4] = new BigInteger("1");
        for(int i=5;i<=10000;i++)
        {
            a[i]=a[i-1].add(a[i-2].add(a[i-3].add(a[i-4])));
        }
        while(s.hasNext())
        {
            int n=s.nextInt();
            System.out.println(a[n]);
        }
    }
}

hdu1002

import java.util.Scanner;//输入
import java.math.BigInteger;//大整数类
import java.math.BigDecimal;//大浮点数类
public class Main {
    public static void main(String[] args) {
        Scanner s=new Scanner(System.in);
        BigInteger[] a = new BigInteger[1000];
        int t=s.nextInt();
        for(int i=1;i<=t;i++)
        {
            System.out.println("Case "+i+":");
            a[0]=s.nextBigInteger();
            a[1]=s.nextBigInteger();
            System.out.println(a[0]+" + "+a[1]+" = "+a[0].add(a[1]));
            if(i!=t)
                System.out.println();
        }
    }
}

hdu1715

import java.util.Scanner;//输入
import java.math.BigInteger;//大整数类
import java.math.BigDecimal;//大浮点数类
public class Main {
    public static void main(String[] args) {
        Scanner s=new Scanner(System.in);
        BigInteger[] a = new BigInteger[10001];
        a[1]=new BigInteger("1");
        a[2]=new BigInteger("1");
        int t=s.nextInt();
        for(int i=3;i<=1000;i++)
        {
            a[i]=a[i-1].add(a[i-2]);
        }
        for(int i=1;i<=t;i++)
        {
            int n=s.nextInt();
            System.out.println(a[n]);
        }
    }
}

你可能感兴趣的:(ACM_新模板,ACM_大数)