java大数习题

2021-02-07 05:15

阅读:663

标签:next   for   ati   math   cin   scan   http   加法   ted   

大数加法,题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002

import java.math.BigInteger;

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n;
        int count = 1;
        n = sc.nextInt();
        int t=n;
        while (t> 0) {
            BigInteger a = sc.nextBigInteger();
            BigInteger b = sc.nextBigInteger();
            System.out.println("Case " + count+":");
            System.out.println(a + " + " + b + " = " + a.add(b));
            t--;
            if(count!=n)
                System.out.println();
            count++;

        }
    }
}

大数判断(带小数,重要的题目):题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2054

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()) {
            BigDecimal a=sc.nextBigDecimal();
            BigDecimal b=sc.nextBigDecimal();
            if(a.compareTo(b)==0) {
                System.out.println("YES");
            }
            else
                System.out.println("NO");
            
        }
    }
}

大数阶层,题目链接:http://acm.jlnu.edu.cn/problem.php?id=1130

import java.math.BigInteger;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        BigInteger n=new BigInteger("1");
        for (int i = 2; i 

大斐波那契,题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1715

import java.math.BigInteger;
import java.util.Scanner;


public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner cin = new Scanner(System.in);
        
        BigInteger[] nums = new BigInteger[1010];
        nums[1] = new BigInteger("1");
        nums[2] = new BigInteger("1");
        for(int i = 3; i  0)
        {
            T--;
            int n = cin.nextInt();
            System.out.println(nums[n]);
        }

    }

}

java大数习题

标签:next   for   ati   math   cin   scan   http   加法   ted   

原文地址:https://www.cnblogs.com/julyzqy/p/12777449.html


评论


亲,登录后才可以留言!