HDUOJ-----1074 Integer Inquiry

时间:2022-05-05
本文章向大家介绍HDUOJ-----1074 Integer Inquiry,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

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

实现代码如下....

 1 #include<cstdio>
 2 #include<string>
 3 #define maxn 2200
 4 int main()
 5 { 
 6     char a[maxn]={''};
 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)=='')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,'',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 }