读书人

这道题该如何做?

发布时间: 2013-03-22 09:49:50 作者: rapoo

这道题该怎么做??
计算A+B


Input

输入数据有多组。
每组一行,为两个整数A, B, A,B∈[0,32767]。
输入以0 0结束。


Output

输出A+B的值,每组数据之间保留一个空行。
注意,是“之间”,最后只有一个换行


Sample Input



Original

Transformed


1 2
3 4
0 0



Sample Output



Original

Transformed


3

7



[解决办法]
struct addAB
{
int a,b;
friend
istream& operator>>(istream &is,AddAB &ab)
{is>>a>>b;
return is;
}
friend
ostream & operator<<(ostream& os,addAB&ab)
os<<a+b;
return os;
operator bool (){return a
[解决办法]
b;};
bool operator !(){return a==0 && b==0 ;};
}
int main()
{
addAB ab;

cin>>ab;
do
{
}while(ab)



}


[解决办法]
struct addAB
{
int a,b;
friend
istream& operator>>(istream &is,AddAB &ab)
{is>>a>>b;
return is;
}
friend
ostream & operator<<(ostream& os,addAB&ab)
os<<a+b;
return os;
operator bool (){return a
[解决办法]
b;};
bool operator !(){return a==0 && b==0 ;};
}
int main()
{
addAB ab;

cin>>ab;
do
{
cout<<ab;
cin>>ab;
if(ab)cout<<end<<endl;//输出换行加空行
}while(ab)

return 0;
}

读书人网 >C++

热点推荐