c++刷题

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.移动零

相关推荐
progalchemist5 分钟前
Quick SwiftObjective-C测试框架入门教程
开发语言·其他·objective-c·swift
怎么没有名字注册了啊9 分钟前
C++后台进程
java·c++·算法
z日火15 分钟前
Java 泛型
java·开发语言
广药门徒18 分钟前
Linux(含嵌入式设备如泰山派)VNC 完整配置指南:含开机自启动(适配 Ubuntu/Debian 系)
开发语言·php
slim~42 分钟前
CLion实现ini 解析器设计与实现
c++·后端·clion
不做无法实现的梦~42 分钟前
jetson刷系统之后没有浏览器--解决办法
开发语言·javascript·ecmascript
Rubisco..1 小时前
codeforces 2.0
算法
未知陨落1 小时前
LeetCode:98.颜色分类
算法·leetcode
一只小松许️1 小时前
深入理解:Rust 的内存模型
java·开发语言·rust
~kiss~1 小时前
K-means损失函数-收敛证明
算法·机器学习·kmeans