您的位置:首页 > 编程语言 > Java开发

hdu 1047 1042 java 大整数

2016-08-22 09:05 447 查看
Input

The input will consist of at most 100 lines of text, each of which contains a single VeryLongInteger. Each VeryLongInteger will be 100 or fewer characters in length, and will only contain digits (no VeryLongInteger will be negative). 

The final input line will contain a single zero on a line by itself.

 

Output

Your program should output the sum of the VeryLongIntegers given in the input. 

This problem contains multiple test cases!

The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.

The output format consists of N output blocks. There is a blank line between output blocks.

 

Sample Input

1

123456789012345678901234567890
123456789012345678901234567890
123456789012345678901234567890
0

 

Sample Output

370370367037037036703703703670

注意这里的多个样例之间有换行符

import java.io.*;
import java.math.*;
import java.util.*;

public class Main {

public static void main(String args[])
{
String str1,str2;
BigDecimal a,b,c;
Scanner cin=new Scanner(System.in);
int t;
t=cin.nextInt();
for(int i=0;i<t;i++)
{
b=BigDecimal.valueOf(0);
c=BigDecimal.valueOf(0);
a=cin.nextBigDecimal();
while(!a.equals(c))
{
b=b.add(a);
a=cin.nextBigDecimal();
}
System.out.println(b);
if(i!=t-1)
System.out.println();
}
}

}


Input

One N in one line, process to the end of file.

 

Output

For each N, output N! in one line.

 

Sample Input

1
2
3

 

Sample Output

1
2
6

求n的阶乘

import java.io.*;
import java.math.*;
import java.util.*;

public class Main
{
public static void main(String args[])
{
Scanner cin=new Scanner(System.in);
BigDecimal a,b,c;
int n;

while(cin.hasNext())
{
a=BigDecimal.valueOf(1);
b=BigDecimal.valueOf(1);
c=BigDecimal.valueOf(1);
n=cin.nextInt();

for(int i=2;i<=n;i++)
{
b=b.add(c);
a=a.multiply(b);
}
System.out.println(a);
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: