HDU high-precision Summary (Java big data class)

Source: Internet
Author: User

Hdu1002

Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1002

Code:

import java.math.BigInteger;import java.util.Scanner;import java.io.*;public class Main {    public static void main(String[] args) {        Scanner cin = new Scanner(System.in);        while(cin.hasNextInt()){            BigInteger a,b,c;            int t,i;            t=cin.nextInt();            i=1;            while(i<=t){                a=cin.nextBigInteger();                b=cin.nextBigInteger();                c=a.add(b);                System.out.println("Case "+i+":");                System.out.println(a+" + "+b+" = "+c);                if(i<t)System.out.println("");                i++;            }        }    }}

Hdu1042

Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1042

Code:

import java.math.BigInteger;import java.util.Scanner;import java.io.*;public class Main {    public static void main(String[] args) {        Scanner cin = new Scanner(System.in);        BigInteger a,i,t;        BigInteger one = new BigInteger("1");        while(cin.hasNextBigInteger()){            t=cin.nextBigInteger();            i=new BigInteger("1");            a=new BigInteger("1");            int cmp=i.compareTo(t);            while(cmp<=0){                a=a.multiply(i);                i=i.add(one);                cmp=i.compareTo(t);            }            System.out.println(a);        }    }}

Hdu1047

Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1047

Code:

import java.math.BigInteger;import java.util.Scanner;import java.io.*;public class Main {    public static void main(String[] args) {        Scanner cin = new Scanner(System.in);        BigInteger a,b;        int i,t;        BigInteger zero = new BigInteger("0");        while(cin.hasNextInt()){            t=cin.nextInt();            for(i=1;i<=t;i++){                boolean flag=true;                b=zero;                while(flag){                    a=cin.nextBigInteger();                    if(a.compareTo(zero)==0)flag=false;                    b=b.add(a);                }                                    System.out.println(b);                if(i<t)System.out.println("");            }        }    }}

Hdu1063

Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1063

Note that the simplest form is to remove the following 0 and the decimal point before the decimal point smaller than 1.

Code:

import java.math.BigDecimal;import java.util.Scanner;public class Main {    public static void main(String[] args) {        Scanner cin = new Scanner(System.in);        int n,i;        BigDecimal r,a;        BigDecimal one = new BigDecimal("1");        while(cin.hasNextBigDecimal()){            r=cin.nextBigDecimal();            n=cin.nextInt();            a=one;            for(i=1;i<=n;i++)                a=a.multiply(r);            a=a.stripTrailingZeros();            String str=a.toPlainString();            if(str.startsWith("0."))                str=str.substring(1);            System.out.println(str);        }    }}

Hdu1316

Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1316

Code:

import java.math.BigInteger;import java.util.Scanner;public class Main {    public static void main(String[] args) {        Scanner cin = new Scanner(System.in);        int i,j;        BigInteger a,b;        BigInteger f[] = new BigInteger[501];        BigInteger zero = new BigInteger("0");        f[1]=new BigInteger("1");        f[2]=new BigInteger("2");        for(i=3;i<=500;i++)            f[i]=f[i-1].add(f[i-2]);        while(cin.hasNextBigInteger()){            a=cin.nextBigInteger();            b=cin.nextBigInteger();            if(a.compareTo(zero)==0 && b.compareTo(zero)==0)break;            for(j=0,i=1;i<=500;i++){                if(a.compareTo(f[i])<=0 && b.compareTo(f[i])>=0)j++;                if(b.compareTo(f[i])<0)break;            }            System.out.println(j);        }    }}

Hdu1715

Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1715

Code:

import java.math.BigInteger;import java.util.Scanner;public class Main {    public static void main(String[] args) {        Scanner cin = new Scanner(System.in);        int i,j,t;        BigInteger f[] = new BigInteger[1001];        f[1]=new BigInteger("1");        f[2]=new BigInteger("1");        for(i=3;i<=1000;i++)            f[i]=f[i-1].add(f[i-2]);        while(cin.hasNextInt()){            t=cin.nextInt();            for(i=1;i<=t;i++){                j=cin.nextInt();                System.out.println(f[j]);            }        }    }}

Hdu1753

Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1753

Code:

Similarly, the simplest decimal form should be removed from the integer part of the number smaller than 1.

import java.math.BigDecimal;import java.math.BigInteger;import java.util.Scanner;public class Main {    public static void main(String[] args) {        Scanner cin = new Scanner(System.in);        BigDecimal a,b;        BigInteger zero = new BigInteger("0");        while(cin.hasNextBigDecimal()){            a=cin.nextBigDecimal();            b=cin.nextBigDecimal();            a=a.add(b);            a=a.stripTrailingZeros();            String str=a.toPlainString();            if(str.startsWith("0."))                str=str.substring(1);            System.out.println(str);        }    }}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.