17.电话号码的组合
来源于题解思路:
继承
CC14 KiKi设计类继承
#include <iostream>
#include <memory>
using namespace std;
class Shape{
private:
int x;
int y;
};
class Rectangle:public Shape
{
public:
Rectangle(int length,int width)
:Shape()
,_length(length)
,_width(width)
{}
void GetArea()
{
cout<<_length*_width<<endl;
}
protected:
int _length;
int _width;
};
class Circle:public Shape{
public:
Circle(int r)
:Shape()
,_r(r)
{}
void GetArea()
{
cout<<3.14*_r*_r<<endl;
}
private:
int _r;
};
class Square:public Rectangle
{
public:
Square(int len)
:Rectangle(len,len)
{}
void GetArea()
{
cout<<_length*_length<<endl;
}
};
int main() {
int length=0,width=0;
cin>>length>>width;
Rectangle ret(length,width);
ret.GetArea();
int r;
cin>>r;
Circle cir(r);
cir.GetArea();
int len;
cin>>len;
Square le(len);
le.GetArea();
}
// 64 位输出请用 printf("%lld")
双指针算法
283.移动零