前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >HDUOJ-----1074 Integer Inquiry

HDUOJ-----1074 Integer Inquiry

作者头像
Gxjun
发布2018-03-21 11:29:03
5890
发布2018-03-21 11:29:03
举报
文章被收录于专栏:mlml

Integer Inquiry

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 9196    Accepted Submission(s): 2354

Problem 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.  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

Source

East Central North America 1996

这道题题目的意思是要求你求大数的加法,此点没什么难度,但是为啥让无数人错的一塌糊涂勒!!还是在于他奇特的要求:

题目中说道的就不说了;

给出的最后一0,哪里的猫腻还是挺多的...

他直接造成下面的几组奇特数据:

当你输入   3

12

1

0

000

00

0

0

output

13

0

0

实现代码如下....

代码语言:javascript
复制
 1 #include<cstdio>
 2 #include<string>
 3 #define maxn 2200
 4 int main()
 5 { 
 6     char a[maxn]={'\0'};
 7     int  sum[maxn+2]={0};
 8     int  inta[maxn]={0};
 9     int n;
10     scanf("%d",&n);    
11     for(int k=0;k<n;k++)
12     {
13         int i;
14         memset(sum,0,sizeof sum);
15         while(1)
16         {
17            scanf("%s",a);
18            if(*a=='0'&&*(a+1)=='\0')break;
19            
20              int  len=strlen(a)-1;
21            for( i=0 ; i<=len; i++ )
22                inta[i]=a[len-i]-'0';
23            int c=0;  
24            for(i=0 ; i<maxn; i++)
25            {
26                    sum[i]+=inta[i]+c ;
27                    c=sum[i]/10;
28                    sum[i]%=10;
29            }
30              memset(a,'\0',sizeof a);
31              memset(inta,0,sizeof inta);
32         }
33         
34         if(k!=0)puts("");
35         
36         for(i=maxn;sum[i]==0&&i>0;i--);
37         
38         for(int j=i;j>=0;j--)
39              printf("%d",sum[j]);
40          
41              puts("");
42     }
43   return 0;
44 }
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2013-07-19 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Integer Inquiry
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档