Integer Inquiry
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8704 Accepted Submission(s): 2211
``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.)
The final input line will contain a single zero on a line by itself.
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.
1 123456789012345678901234567890 123456789012345678901234567890 123456789012345678901234567890 0
370370367037037036703703703670
//大数相加,化为字符串处理
#include<iostream> #include<string.h> using namespace std; #define MAX 110 int main() { int n,len,i,flag,tlen; char s[MAX]; int sum[MAX]; while(cin>>n) { while(n--) { memset(sum,sizeof(sum)); len=0; while(cin>>s&&strcmp(s,"0")) { tlen=strlen(s); if(tlen>len) len=tlen; for(i=tlen-1;i>=0;i--) { sum[tlen-1-i]+=s[i]-'0'; if(sum[tlen-1-i]>9) { sum[tlen-1-i]%=10; sum[tlen-i]+=1; } } } tlen=0; for(i=len+6;i>=0;i--) { if(sum[i]&&tlen==0) tlen=1; if(tlen||i==0) cout<<sum[i]; } cout<<endl; if(n>0) cout<<endl; } } return 0; }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。