首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

A+B 有关问题(HDU ACM)

2013-06-25 
A+B 问题(HDU ACM)内容贴http://acm.hdu.edu.cn/showproblem.php?pid1000#include iostreamusing names

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;
}

热点排行