| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1986 人关注过本帖
标题:杭州电子科技大学ACM网站上的1047题无法提交成功, 题目是高精度加法。题目如 ...
取消只看楼主 加入收藏
好孩子好宝贝
Rank: 1
等 级:新手上路
帖 子:35
专家分:2
注 册:2011-7-26
结帖率:87.5%
收藏
已结贴  问题点数:20 回复次数:4 
杭州电子科技大学ACM网站上的1047题无法提交成功, 题目是高精度加法。题目如下
Integer Inquiry
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4555    Accepted Submission(s): 1090


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
 




#include<iostream>
using namespace std;
#define T 110
char a[110][101],p[T];
int d[110];
int k,i,j,R;
int main()
{
    freopen("D:\\in.txt","r",stdin);
    scanf("%d",&R);
    while(R--)
    {
        k=0;
        getchar();
        while(1)
        {
           scanf("%s",a[++k]);
           if(strcmp(a[k],"0")==0)  break;
        }
        int max_len=0;
        for(i=1;i<k;i++)
        {
             d[i]=strlen(a[i]);
             if(d[i]>max_len)
                  max_len=d[i];

        }
        for(i=1;i<k;i++)
        {
            for(j=0;j<d[i];j++)
                a[i][j]-='0';
        }
        memset(p,0,sizeof(p));
        for(i=max_len-1;i>=0;i--)
        {
            for(j=1;j<k;j++)
            {
                if(d[j]>0)
                {
                    p[i]+=a[j][--d[j]];
                }
            }
        }
        for(i=max_len-1;i>0;i--)
        {
            p[i-1]+=p[i]/10;
            p[i]=p[i]%10;
        }
        if(p[0]>=10)
        {
            printf("%d",p[0]/10);
            p[0]=p[0]%10;
        }
        for(i=0;i<=max_len-1;i++)
        {
            printf("%d",p[i]);
        }
        printf("\n");
        if(R!=0) printf("\n");
    }
    return 0;

}
搜索更多相关主题的帖子: 成功 大学 explored numbers Memory 
2011-08-19 09:57
好孩子好宝贝
Rank: 1
等 级:新手上路
帖 子:35
专家分:2
注 册:2011-7-26
收藏
得分:0 
对,牛人你太牛啦。。
2011-08-20 10:24
好孩子好宝贝
Rank: 1
等 级:新手上路
帖 子:35
专家分:2
注 册:2011-7-26
收藏
得分:0 
2

100
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
999999999999999999999999999999999999999999999
0

11
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111
0

我该啦,但是还是错啦。。。上面我测试数据:
#include<iostream>
using namespace std;
#define T 110
char a[110][110];
int d[110],p[T];
int k,i,j,R;
int main()
{
    freopen("D:\\in.txt","r",stdin);
    scanf("%d",&R);
    while(R--)
    {
        k=0;
        getchar();
        while(1)
        {
           scanf("%s",a[++k]);
           if(strcmp(a[k],"0")==0)  break;
        }
        int max_len=0;
        for(i=1;i<k;i++)
        {
             d[i]=strlen(a[i]);
             if(d[i]>max_len)
                  max_len=d[i];

        }
        for(i=1;i<k;i++)
        {
            for(j=0;j<d[i];j++)
                a[i][j]-='0';
        }
        memset(p,0,sizeof(p));
        for(i=max_len-1;i>=0;i--)
        {
            for(j=1;j<k;j++)
            {
                if(d[j]>0)
                {
                    p[i]+=a[j][--d[j]];
                }
            }
        }
        for(i=max_len-1;i>0;i--)
        {
            p[i-1]+=p[i]/10;
            p[i]=p[i]%10;
        }
        if(p[0]>=10)
        {
            printf("%d",p[0]/10);
            p[0]=p[0]%10;
        }
        for(i=0;i<=max_len-1;i++)
        {
            printf("%d",p[i]);
        }
        printf("\n");
        if(R!=0) printf("\n");
    }
    return 0;

}
2011-08-20 16:39
好孩子好宝贝
Rank: 1
等 级:新手上路
帖 子:35
专家分:2
注 册:2011-7-26
收藏
得分:0 
?????????大哥,我没有看到什么啊,就是看到R的值输出来的啊。麻烦牛人给组测试数据
2011-08-22 20:09
好孩子好宝贝
Rank: 1
等 级:新手上路
帖 子:35
专家分:2
注 册:2011-7-26
收藏
得分:0 
图片附件: 游客没有浏览图片的权限,请 登录注册
没有奇怪啊。。。。结果不是
1000000000000000000000000000000000000000000000000000000000

1111111111111111111111111111111111111111111111111111111111
吗???????
按你的改成那个后就变成啦:
1000000000000000000000000000000000000000000000000000000000
1
1111111111111111111111111111111111111111111111111111111111
为什么奇怪啊?????求牛人解。。。。。。。。。
2011-08-23 21:02
快速回复:杭州电子科技大学ACM网站上的1047题无法提交成功, 题目是高精度加法。 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019023 second(s), 11 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved