c++题目,请高手指点!!!
来源:百度知道 编辑:UC知道 时间:2024/05/27 12:34:08
Problem Description
Calculate A + B.
Input
Each line will contain two integers A and B. Process to end of file.
Output
For each case, output A + B in one line.
Sample Input
1 1
Sample Output
2
我的东西,提交后是错的,为什么啊!!!
#include<iostream>
using namespace std;
main()
{
int a,b;
cin>>a>>b;
cout<<a+b<<endl;
}
还是错的,acm的题真变态!!
Calculate A + B.
Input
Each line will contain two integers A and B. Process to end of file.
Output
For each case, output A + B in one line.
Sample Input
1 1
Sample Output
2
我的东西,提交后是错的,为什么啊!!!
#include<iostream>
using namespace std;
main()
{
int a,b;
cin>>a>>b;
cout<<a+b<<endl;
}
还是错的,acm的题真变态!!
试试这样
#include<iostream>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
cout<<a+b<<endl;
return 0;
}
#include<iostream>
using namespace std;
main()
{
int a,b;
cin>>a>>b;
cout<<a<<'+'<<b<<'='<<a+b<<endl;
}
不要输出endl,这个程序里没有要求你换行,你输出了就错。
关键是这句:Process to end of file. 多case题目,读到文件尾结束,这个是ACM里常用的格式,我的写法是这样的:
#include<stdio.h>
int a,b;
int main()
{
while (scanf("%d%d",&a,&b)==2)
printf("%d\n",a+b);
return 0;
}
scanf函数返回的是读到的变量的个数。