输入样例: 1 2
3 4
输出样例: [1,2] -> 6 [3,4] -> 14
注意:“->”前后各有一个空格,输出中每行结束有一个换行(参见代码main函数)。
代码框架如下:
namespace myns
{
class COUT
{
public:
COUT() {}
};
COUT cout;
}
class A
{
public:
A(int x, int y) : w(x), h(y) {}
int getLen() const
{
if (len < 0)
len = 2 * (w + h);
return len;
}
private:
friend myns::COUT &operator<<(myns::COUT &cout, const A &a);
int w, h;
mutable int len = -1;
};
//todo 写下你的cout 输出重载实现
using myns::cout;
using std::cin;
int main()
{
int x, y;
cin >> x >> y;
A a1(x, y);
cout << a1 << "\n";
cin >> x >> y;
A a2(x, y);
cout << a2 << "\n";
return 0;
}