| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1182 人关注过本帖
标题:HDOJ上的A+B题,应该没问题的,怎么就是通不过?
只看楼主 加入收藏
狂人老大
Rank: 1
来 自:杭州
等 级:新手上路
威 望:1
帖 子:394
专家分:0
注 册:2007-6-21
收藏
 问题点数:0 回复次数:7 
HDOJ上的A+B题,应该没问题的,怎么就是通不过?

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

21 2112233445566778899 998877665544332211


Sample Output

Case 1:1 + 2 = 3Case 2:112233445566778899 + 998877665544332211 = 1111111111111111110我的答案是:#include<stdio.h>
int main()
{
 __int64 A,B;
 int T,i=1;
 while((scanf("%d",&T))!=EOF)
 {
  for(i=0;i<T;i++)
  {
   scanf("%I64d%I64d",&A,&B);
   printf("Case %d:\n",i+1);
   printf("%I64d + %I64d = %I64d\n\n",A,B,A+B);
  }
 }
 return 0;
} 还有就是:#include<stdio.h>
int main()
{
 int T,i,j;
 __int64 A[20],B[20];
 while((scanf("%d",&T))!=EOF)
 {
  for(i=0;i<T;i++)
   scanf("%I64d%I64d",&A[i],&B[i]);
  for(j=0;j<T;j++)
  {
   printf("Case %d:\n",j+1);
   printf("%I64d + %I64d = %I64d\n\n",A[j],B[j],A[j]+B[j]);
  }
 }
 return 0;
} 请大家多多指教,谢谢了
搜索更多相关主题的帖子: HDOJ 
2007-11-24 21:16
狂人老大
Rank: 1
来 自:杭州
等 级:新手上路
威 望:1
帖 子:394
专家分:0
注 册:2007-6-21
收藏
得分:0 
知道了
You may assume the length of each integer will not exceed 1000.的是意思是大数的位数要在1000位以内
题目理解错了   要用数组来做的

ACMer的QQ群:33741351
单片机QQ群:55130117
2007-11-24 23:37
狂人老大
Rank: 1
来 自:杭州
等 级:新手上路
威 望:1
帖 子:394
专家分:0
注 册:2007-6-21
收藏
得分:0 
还是这个问题啊    要把每一位数字放入数组里的吧    应该怎么做呢??
设A[1000]   如何使输入200位数字后判断输入结束呢???

ACMer的QQ群:33741351
单片机QQ群:55130117
2007-11-27 22:23
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 
大数的加法啦.

倚天照海花无数,流水高山心自知。
2007-11-27 22:41
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 
看看这个可以不啦.输出格式自己改下.
程序代码:
#include<stdio.h>
#include<string.h>

typedef struct Big_num{
    int data[1001];
    int len;
  };
void char_num(Big_num &a,char *str)
{
    int i=0;
    a.len=strlen(str);
    for(i=0;i<a.len;i++)
    {
        a.data[i]=str[a.len-i-1]-'0';
    }
}

void Add_Big_Num(Big_num &a,Big_num &b)
{
    int len,i,temp=0;
    while(a.len<b.len)
    {
        a.data[a.len++]=0;
    }
    while(a.len>b.len)
    {
        b.data[b.len++]=0;
    }

    for(i=0;i<a.len;i++)
    {
        int flag=a.data[i]+b.data[i]+temp;
        a.data[i]=flag%10;
        temp=flag/10;
    }
    if(temp)
    {
        a.data[a.len++]=temp;
    }
}
        
        
int main()
{
    char str1[301],str2[301];
    Big_num a,b;
    while(EOF!=(scanf("%s%s",str1,str2)))
    {
         char_num(a,str1);
         char_num(b,str2);
         Add_Big_Num(a,b);
         while(--a.len>=0)
         {
            printf("%d",a.data[a.len]);
         }
         printf("\n");
    }
    return 0;
}

倚天照海花无数,流水高山心自知。
2007-11-27 22:53
狂人老大
Rank: 1
来 自:杭州
等 级:新手上路
威 望:1
帖 子:394
专家分:0
注 册:2007-6-21
收藏
得分:0 
  谢谢了

ACMer的QQ群:33741351
单片机QQ群:55130117
2007-11-27 22:57
狂人老大
Rank: 1
来 自:杭州
等 级:新手上路
威 望:1
帖 子:394
专家分:0
注 册:2007-6-21
收藏
得分:0 
  知道了   应该用字符串才行的啊

ACMer的QQ群:33741351
单片机QQ群:55130117
2007-11-28 12:39
狂人老大
Rank: 1
来 自:杭州
等 级:新手上路
威 望:1
帖 子:394
专家分:0
注 册:2007-6-21
收藏
得分:0 
回复 5# 的帖子
为什么要写成str1[301],str2[301];这样呢???
为什么是301而不是1000???

ACMer的QQ群:33741351
单片机QQ群:55130117
2007-11-29 20:11
快速回复:HDOJ上的A+B题,应该没问题的,怎么就是通不过?
数据加载中...
 
   



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

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