| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 652 人关注过本帖
标题:求A+B的程序总是出现错误,有输入输出案例,求解释what's wrong...
只看楼主 加入收藏
yenga
Rank: 1
等 级:新手上路
帖 子:39
专家分:7
注 册:2013-11-25
结帖率:75%
收藏
已结贴  问题点数:5 回复次数:9 
求A+B的程序总是出现错误,有输入输出案例,求解释what's wrong...
#include"stdio.h"
int main()
{
int i,n;
long int a,b;
scanf("%d",&n);
for(i=1;i<n;i++)
{
scanf("%ld%ld",&a,&b);
printf("Case %d:\n",i);
printf("%d+%d=%d",a,b,a+b);
printf("\n");
}
scanf("%ld%ld",&a,&b);
printf("Case%d:\n",n);
printf("%d+%d=%d",a,b,a+b);
return 0;
}





Sample Input
2
1 2
112233445566778899 998877665544332211



Sample Output
Case 1:
1 + 2 = 3

Case 2:
112233445566778899 + 998877665544332211 = 1111111111111111110


提交失败

[ 本帖最后由 yenga 于 2013-11-26 14:03 编辑 ]
搜索更多相关主题的帖子: include return wrong 
2013-11-26 14:01
yenga
Rank: 1
等 级:新手上路
帖 子:39
专家分:7
注 册:2013-11-25
收藏
得分:0 
http://acm.hdu.




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
2013-11-26 14:11
yenga
Rank: 1
等 级:新手上路
帖 子:39
专家分:7
注 册:2013-11-25
收藏
得分:0 
输出的空格问题我也修改过了,但还是提交不了
2013-11-26 14:11
xixiqiqi
Rank: 2
等 级:论坛游民
帖 子:22
专家分:71
注 册:2013-10-10
收藏
得分:1 
楼主输入的数据太大了,long int类型在有些编译器下只分配4个字节,在有符号的情况下范围只有(十进制)-2147483648~2147483547
2013-11-26 14:46
czz5242199
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:4
帖 子:660
专家分:2400
注 册:2011-10-26
收藏
得分:1 
You may assume the length of each integer will not exceed 1000.
2013-11-26 15:20
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9024
专家分:54030
注 册:2011-1-18
收藏
得分:1 
还“提交失败”!
你提交之前不先用给出的例子进行一下测试?
2013-11-26 15:41
流年!
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:41
专家分:107
注 册:2013-11-7
收藏
得分:1 
我运行没错啊
2013-11-26 16:09
azzbcc
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:江西财经大学
等 级:贵宾
威 望:81
帖 子:3293
专家分:12919
注 册:2012-11-4
收藏
得分:1 
题目说了,数据可能是1000位的整数


[fly]存在即是合理[/fly]
2013-11-26 19:20
wht750109
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:49
专家分:151
注 册:2013-10-21
收藏
得分:1 
#include"stdio.h"
int main()
{
int i,n;
long int a,b;
scanf("%d",&n);
for(i=1;i<n;i++)
{
scanf("%ld%ld",&a,&b);
printf("Case %d:\n",i);
printf("%d+%d=%d",a,b,a+b);    应该为printf("%ld+%ld=%ld",a,b,a+b);   
printf("\n");
}
scanf("%ld%ld",&a,&b);
printf("Case%d:\n",n);
printf("%d+%d=%d",a,b,a+b);   应该为printf("%ld+%ld=%ld",a,b,a+b);
return 0;
}

2013-11-26 22:14
thb
Rank: 2
等 级:论坛游民
帖 子:26
专家分:31
注 册:2013-11-21
收藏
得分:0 
不把他们当做数字,当做字符串输入,然后自己设计算法手动加法
2013-11-27 23:39
快速回复:求A+B的程序总是出现错误,有输入输出案例,求解释what's wrong...
数据加载中...
 
   



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

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