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
注意这里的多个样例之间有换行符
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);
}
}
}
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);
}
}
}
相关文章推荐
- OJ---- 201301 JAVA 题目2-3级(走棋盘)
- java反射机制及在Abdroid的应用
- JavaEE版Eclipse搭建SSH框架详解
- Java读取文件MD5的两种方案
- Java的环境变量配置
- 20145234黄斐《Java程序设计》第四周学习总结
- Spring学习进阶(四) Spring JDBC
- Java知识点22
- Java
- struts2 s:if标签以及 #,%{},%{#}的使用方法等在资料整理
- Zookeeper Java客户端API的使用
- Zookeeper Java客户端API的使用
- Struts学习总结-02 上传文件
- JavaSE 基础笔记 day03
- spring tool suite在线安装
- Java读取properties配置文件
- 06_Java中文件上传与下载
- Java随机生成长度不少于6的指定长度的密码,且这个字符串必须包含大小写字母、数字和特殊字符,四种的任意三种
- Myeclipse中怎样隐藏碍眼的jar包
- Java爬虫到一些总结和心得