poj2106,Poj 1503 Integer Inquiry

 2023-10-06 阅读 24 评论 0

摘要:1.鏈接地址: http://poj.org/problem?id=1503 2.題目: Integer Inquiry Time Limit: 1000MS?Memory Limit: 10000KTotal Submissions: 28115?Accepted: 10925 Description One of the first users of BIT's new supercomputer was Chip Diller. He exte

1.鏈接地址:

http://poj.org/problem?id=1503

2.題目:

Integer Inquiry
Time Limit: 1000MS?Memory Limit: 10000K
Total Submissions: 28115?Accepted: 10925

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

Source

East Central North America 1996

3.思路:

4.代碼:

 1 #include "stdio.h"
 2 #include "string.h"
 3 #define NUM 102
 4 int a[NUM];
 5 int main()
 6 {
 7     char b[102];
 8     int len;
 9     int max=0;
10     int i;
11     gets(b);
12     while(b[0]-'0'!=0 || strlen(b)!=1)
13     {
14         len = strlen(b);
15         for(i=len-1;i>=0;i--)
16         {
17             a[len-1-i]+=b[i]-'0';
18             if(a[len-1-i]>=10) {a[len-1-i+1]++;a[len-1-i]-=10;}
19         }
20         i=len;
21         while(a[i]>=10){a[i+1]++;a[i]-=10;i++;}
22         gets(b);        
23     }
24     i=NUM-1;
25     while(a[i]==0)i--;
26     while(i>=0)
27     {
28         printf("%c",a[i]+'0');
29         i--;
30     }
31    return 0;
32 }

?

轉載于:https://www.cnblogs.com/mobileliker/p/3556808.html

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/5/118758.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息