| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 584 人关注过本帖
标题:杭电1002问题求指点。
取消只看楼主 加入收藏
既生瑜何生亮
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2012-2-7
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:1 
杭电1002问题求指点。
Problem Description
I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.

 

Input
The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000.

 

Output
For each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line is the an equation "A + B = Sum", Sum means the result of A + B. Note there are some spaces int the equation. Output a blank line between two test cases.

 

Sample Input
2
1 2
112233445566778899 998877665544332211
 

Sample Output
Case 1:
1 + 2 = 3

Case 2:
112233445566778899 + 998877665544332211 = 1111111111111111110
http://acm.hdu.

#include<stdio.h>
#include<string.h>
#define N 1001
char a[N], b[N];
int c[N]={0}, d[N]={0};
int main()
{
    int i, j, m, n, t, h, k, l1, l2;
    scanf("%d", &h);
    for(i = 1; i <= h; i++)
    {
        scanf("%s",a);
        scanf("%s",b);
        l1 = strlen(a);
        l2 = strlen(b);
        if(l1 < l2)
            k = l2;
        else
            k = l1; t = k;
        for(j = 0;j < l1; k--,j++)
            c[k] = a[l1-1-j] - '0';
        k = t;
        for(j = 0;j < l2; k--,j++)
            d[k] = b[l2-1-j] - '0';
        for(j = t; j >= 0; j--)
        {
            c[j] += d[j];
            if(c[j] >= 10)
            {
                c[j] -= 10;
                c[j-1]++;
            }
        }
        printf("Case %d:\n", i);
        printf("%s + %s = ", a, b);
        if(c[0] == 0)
            for(j = 1; j <= t; j++)
                printf("%d",c[j]);
            else
                for(j = 0; j <= t; j++)
                    printf("%d",c[j]);
                printf("\n");
                if(i != h)
                    printf("\n");
                }
    return 0;
}
为什么自己运行的对,但是提交后wrong呢。
搜索更多相关主题的帖子: process positive problem 1002 1000 
2012-08-04 08:47
既生瑜何生亮
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2012-2-7
收藏
得分:0 
回复 3楼 demonleer
多谢了。回去仔细研读一下。
2012-08-05 17:45
快速回复:杭电1002问题求指点。
数据加载中...
 
   



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

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