HDU 1047 Integer Inquiry
2016-05-10 20:13
363 查看
Integer Inquiry
Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d
& %I64u
Submit Status
Description
One of the first users of BIT's new supercomputer was Chip Diller. He extended his exploration of powers of 3 to go from 0 to 333 and he explored taking various sums of those numbers.
``This supercomputer is great,'' remarked Chip. ``I only wish Timothy were here to see these results.'' (Chip moved to a new apartment, once one became available on the third floor of the Lemon Sky apartments on Third Street.)
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.
Sample Input
Sample Output
大数相加问题:
JAVA:
Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d
& %I64u
Submit Status
Description
One of the first users of BIT's new supercomputer was Chip Diller. He extended his exploration of powers of 3 to go from 0 to 333 and he explored taking various sums of those numbers.
``This supercomputer is great,'' remarked Chip. ``I only wish Timothy were here to see these results.'' (Chip moved to a new apartment, once one became available on the third floor of the Lemon Sky apartments on Third Street.)
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.
Sample Input
123456789012345678901234567890 123456789012345678901234567890 123456789012345678901234567890 0
Sample Output
370370367037037036703703703670
大数相加问题:
#include<string.h> #include<stdio.h> #include<stdlib.h> char str[105],sum[105],ssum[105]; int main(){ char c; int len,i,flag,slen,k,j; //memset(sum,'0',sizeof(sum)); flag=1; while(~scanf("%s",str)){ len=strlen(str); if(len==1&&str[0]=='0') break; if(flag){ strcpy(sum,str); flag=0; } else{ slen=strlen(sum); for(k=0;len>=0||slen>=0;len--,slen--,k++){ if(len>=0&&slen>=0) ssum[k]=str[len]+sum[slen]-'0'+c; if(len<0&&slen>=0) ssum[k]=sum[slen]+c; if(len>=0&&slen<0) ssum[k]=str[len]+c; c=0; //进位加上之后要清零 if(ssum[k]>'9'){ ssum[k]-=10; c=1; } } if(c==1) ssum[k]='1'; for(i=strlen(ssum)-1,j=0;i>=0,j<strlen(ssum)-1;j++,i--){ sum[j]=ssum[i]; } //printf("%s\n",sum); } } printf("%s\n",sum); return 0; }
JAVA:
import java.io.*; import java.math.*; class Bigint { public static void main(String[] args) throws Exception{ String s1 = null; BigInteger bint = null; BufferedReader bin = new BufferedReader(new InputStreamReader(System.in)); s1 = bin.readLine(); while(!s1.equals("0")) { if(bint == null) { bint = new BigInteger(s1); } else { bint = bint.add(new BigInteger(s1)); } s1 = bin.readLine(); } if(s1.equals("0")) { System.out.println(bint.toString()); } } }
相关文章推荐
- ./i2cdetect -y 2 Error: Can't use SMBus Quick Write command on this bus
- HDU 4390 Number Sequence
- Highlighter与BooleanQuery查询
- iOS开发 - 第01篇 - UI基础 - 03 - 应用程序管理
- easyui的treegrid,只能出来父节点,子节点出不来
- iOS学习笔记之四--UIView的常见属性
- 浅谈Lucene中的DocValues
- 小米5月10日发布会--miui8
- 三种自定义UITableViewCell的方法
- POJ 2533 Longest Ordered Subsequence【最长递增子序列】【DP思想】
- iOS UIKit:TableView之表格创建(1)
- UI、ID、UE和GUI,这些都是什么
- 【康拓逆展开】HDU2062Subset sequence
- Hibernate中Caused by: java.sql.SQLException: Field 'address_id'doesn't have a default value
- UItextField实时监控输入框的文字
- UITextField的使用详解
- mongoVUE:未将对象引用设置到对象的实例
- HDU 2767 Proving Equivalences (强联通)
- vueJs源码解读0-1
- Android Studio --- Gradle Build Running 死机问题