POJ 1503
发布日期:2021-06-30 15:30:54 浏览次数:2 分类:技术文章

本文共 1691 字,大约阅读时间需要 5 分钟。

Integer Inquiry

Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 36407   Accepted: 14175

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

1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678900

Sample Output

370370367037037036703703703670

Source

#include
using namespace std;#include
#include
int main(){ // freopen("1.txt","r",stdin);char a[110];int s[110]={0},la,ls=0;while(cin>>a){ la=strlen(a)-1; if(a[0]=='0'&&la==0) break; ls=0; for(int i=la;i>=0;i--) s[ls++]+=(a[i]-'0');}for(int i=109;i>=0;i--) if(s[i]!=0){ ls=i; break; } int k=0; while(k<=ls){ if(s[k]>=10){ s[k+1]+=s[k]/10; s[k]%=10; } k++; } while(s[ls+1]!=0){ ls++; if(s[ls-1]>10){ s[ls]+=s[ls-1]/10; s[ls-1]%=10; } } for(int i=ls;i>=0;i--) cout<

 

转载地址:https://joycez.blog.csdn.net/article/details/82807304 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:POJ 2109
下一篇:POJ 3087

发表评论

最新留言

留言是一种美德,欢迎回访!
[***.207.175.100]2024年04月26日 18时05分00秒