問題及代碼:
Problem R: P3 數錢是件愉快的事
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 356 Solved: 189
[Submit][Status][Web Board]
Description
Input
Output
Sample Input
4 16 14
12 17 9
Sample Output
574<-->4*100+16*10+14
1379<-->12*100+17*10+9
1953<-->16*100+33*10+23
HINT
#include<iostream>
using namespace std;
class Money
{
private:
int hundred; //百元張數
int ten; //拾百元張數
int one; //壹元張數
public:
Money(int h=0,int t=0, int o=0);
Money operator+(const Money &m);
friend ostream &operator<<(ostream &out,Money m);
};
//************* begin *****************
Money ::Money(int h,int t,int o)
{
hundred=h;
ten=t;
one=o;
}
Money Money::operator+(const Money &m)
{
return Money(hundred+m.hundred,ten+m.ten,one+m.one);
}
ostream &operator << (ostream &out,Money m)
{
out<<m.hundred*100+m.ten*10+m.one<<"<-->"<<m.hundred<<"*100+"<<m.ten<<"*10+"<<m.one;
return out;
}
//************* end *****************
int main()
{
int mh1, mt1, mo1, mh2, mt2,mo2;
cin>>mh1>>mt1>>mo1;
cin>>mh2>>mt2>>mo2;
Money m1(mh1, mt1, mo1), m2(mh2, mt2,mo2);
cout<<m1<<endl;
cout<<m2<<endl;
Money m3;
m3=m1+m2;
cout<<m3<<endl;
return 0;
}
運行結果: