A+B 问题(HDU ACM)
内容贴http://acm.hdu.edu.cn/showproblem.php?pid=1000
#include <iostream>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
int sum=0;
sum=a+b;
cout<<sum<<endl;
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
long int sum=0;
sum=a+b;
cout<<sum<<endl;
return 0;
}
#include <iostream>
using namespace std;
int sum(const int &a,const int &b)
{
if((a&b) == 0) return a^b;
else
return sum((a^b),((a&b)<<1));
}
int main()
{
int a,b;
cin>>a>>b;
cout<<sum(a,b)<<endl;
return 0;
}
我用了三种方式,都是wrong answer,这ACM网站到底怎么编译的?谁能给我解释这是为什么呢
[解决办法]
每行一个输入啊, 你读个 n 干什么....
这样不就行了么:
#include <iostream>
int main()
{
int a,b;
while(std::cin >> a >> b)
{
std::cout << a + b << std::endl;
}
return 0;
}
[解决办法]
恩,可能输入多个数据的,每个数据在一行,然后每行输出A+B。要看懂题目的。
[解决办法]
#include <iostream>
using namespace std;
int main(){
int a, b;
while(cin>>a>>b) cout<<a+b<<endl;
return 0;
}