zoukankan      html  css  js  c++  java
  • Java大数练习

    大数阶乘

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=28

     1 import java.io.*;
     2 import java.util.*;
     3 import java.math.*;
     4 //import java.text.*;
     5 
     6 public class Main {
     7 
     8     /**
     9      * @param args
    10      */
    11     public static void main(String[] args) throws Exception{
    12         // TODO Auto-generated method stub
    13         Scanner cin = new Scanner (System.in);
    14         PrintWriter cout = new PrintWriter(System.out);
    15         
    16         int n = cin.nextInt();
    17         BigInteger ans = BigInteger.ONE;
    18         for(int i=1;i<=n;i++)
    19             ans = ans.multiply(BigInteger.valueOf(i));
    20         cout.println(ans);
    21         cout.flush();
    22     }
    23 
    24 }

    比较大小

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=73

     1 import java.io.*;
     2 import java.util.*;
     3 import java.math.*;
     4 import java.text.*;
     5 
     6 public class Main {
     7 
     8     /**
     9      * @param args
    10      */
    11     public static void main(String[] args) {
    12         // TODO Auto-generated method stub
    13         Scanner cin = new Scanner(System.in);
    14         while(true)
    15         {
    16             BigInteger a = cin.nextBigInteger();
    17             BigInteger b = cin.nextBigInteger();
    18             if(a.equals(BigInteger.ZERO) && b.equals(BigInteger.ZERO) )
    19             {
    20                 break;
    21             }
    22             int flag = a.compareTo(b);
    23             if(flag == 0)
    24                 System.out.println("a==b");
    25             else if(flag == -1)
    26                 System.out.println("a<b");
    27             else 
    28                 System.out.println("a>b");
    29         }
    30     }
    31 
    32 }

    大数加法

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=103

     1 import java.io.*;
     2 import java.util.*;
     3 import java.math.*;
     4 
     5 
     6 public class Main {
     7 
     8     /**
     9      * @param args
    10      */
    11     public static void main(String[] args) {
    12         // TODO Auto-generated method stub
    13             Scanner cin = new Scanner(System.in);
    14             int T = cin.nextInt();
    15             int cas = 1;
    16             for(int i=1;i<=T;i++)
    17             {
    18                 BigInteger a = cin.nextBigInteger();
    19                 BigInteger b = cin.nextBigInteger();
    20                 BigInteger ans = a.add(b);
    21                 
    22                 System.out.println("Case "+i+":");
    23                 System.out.println(a+" + "+b+" = "+ans);
    24             }
    25     }
    26 
    27 }
  • 相关阅读:
    【AGC010 C】Cleaning
    【未知来源】火神的鱼
    【2017 北京集训 String 改编版】子串
    【未知来源】记忆
    【2017 江苏集训】子串
    【未知来源】循环移位
    【未知来源】K-th String
    【hdu 6067】Big Integer
    【CERC 2014 E】2048
    【hdu 6155】Subsequence Count
  • 原文地址:https://www.cnblogs.com/helica/p/5242583.html
Copyright © 2011-2022 走看看