| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 551 人关注过本帖
标题:hdu1047 大数相加问题,不怎么为什么wa
只看楼主 加入收藏
清尘
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2013-9-5
结帖率:66.67%
收藏
已结贴  问题点数:5 回复次数:2 
hdu1047 大数相加问题,不怎么为什么wa
题目
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.)
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.
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.
1

123456789012345678901234567890
123456789012345678901234567890
123456789012345678901234567890
0
370370367037037036703703703670
代码:
#include<stdio.h>
#include<string.h>
int num0[102][102];
int num1[105];
char str[105];
int main()
{
    int n;
    int i,j,k,l;
    int len;
    int maxlen;
    int temp;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        maxlen=0;
        for(j=0;j<105;j++)
            num1[j]=0;
        j=0;
        while(scanf("%s",str),strcmp(str,"0"))
        {
            len=strlen(str);
            if(len>maxlen)
                maxlen=len;
            for(k=0;k<len;k++)
            {
                num0[j][len-1-k]=str[k]-'0';
            }
            j++;
        }
        temp=0;
        for(k=0;k<maxlen;k++)
        {
            num1[k]+=temp;
            for(l=0;l<j;l++)
            {
                num1[k]+=num0[l][k];
            }
            temp=num1[k]/10;
            num1[k]%=10;
        }
        while(temp)
        {
            num1[k]+=temp%10;
            temp/=10;
            k++;
        }
        if(i)
            printf("\n");
        if(j)
        {
            for(l=k-1;l>=0;l--)
                printf("%d",num1[l]);
            printf("\n");
        }
        else
            printf("0\n");
    }

    return 0;
}
搜索更多相关主题的帖子: available explored numbers powers single 
2013-09-13 17:57
pauljames
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:千里冰封
威 望:9
帖 子:1555
专家分:10000
注 册:2011-5-8
收藏
得分:3 
你先换成小点的数试试原理是否可行

经常不在线不能及时回复短消息,如有c/单片机/运动控制/数据采集等方面的项目难题可加qq1921826084。
2013-09-14 17:24
guhemeng
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:100
专家分:165
注 册:2013-7-27
收藏
得分:3 
  楼主想干什么wa ???????????
2013-09-14 18:38
快速回复:hdu1047 大数相加问题,不怎么为什么wa
数据加载中...
 
   



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

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