Chinaunix首页 | 论坛 | 博客
  • 博客访问: 350667
  • 博文数量: 122
  • 博客积分: 5000
  • 博客等级: 大校
  • 技术积分: 1191
  • 用 户 组: 普通用户
  • 注册时间: 2009-10-24 11:12
文章分类

全部博文(122)

文章存档

2010年(122)

我的朋友

分类: C/C++

2010-03-30 21:11:27

一、问题描述

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

二、代码

 

#include<iostream>
#include<string>
using namespace std;
char a[101];
char O[105];
int N=104;
int main()
{

    int i;
    int len;
    memset(O,48,sizeof(O));
    cin>>a;
    while(strcmp(a,"0")!=0)
    {
        len=strlen(a);
        for(i=1;i<=N;++i)
        {
            if(i<=len)
                O[N-i]=a[len-i]+O[N-i]-48;
            if(O[N-i]>=58)
            {
                O[N-i]-=10;
                    O[N-i-1]+=1;
            }
        }
        cin>>a;
    }
    O[N]='\0';
    for(i=0;i<N;++i)
    {
        if(O[i]!=48)
            break;
    }
    if(i==N)
        cout<<0<<endl;
    else
        cout<<O+i<<endl;
    return 0;
}


阅读(1481) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~