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

相关推荐
一只旭宝6 分钟前
预约系统版本2(基于第一版改良)
服务器·数据库·c++
Nil20814 分钟前
leetcode 230二叉搜索树中第k小的元素
算法·leetcode·职场和发展
被怪兽吃掉了15 分钟前
5.2.1一维组数定义方式
开发语言·c++·算法
不会就选b18 分钟前
Linux之线程进阶---封装信号量
数据结构·算法
不会就选b20 分钟前
算法日常・每日刷题--<BFS&&最短路径>4
算法·宽度优先
旖旎夜光23 分钟前
LeetCode 69:x 的平方根(二分查找) —— 题解
数据结构·c++·算法·leetcode·二分查找
TheBestRucy23 分钟前
Python 九阳神功之肆:网络编程 · Socket 从入门到实战
开发语言·网络·python
j7~26 分钟前
【C++】《C++二叉搜索树(BST)从入门到精通:概念、实现与Key/Value模型全解析》
开发语言·c++·学习·二叉搜索树
hehelm27 分钟前
仿muduo库实现高并发服务器—Channel类
linux·服务器·开发语言·网络·c++
末代iOS程序员华仔29 分钟前
Codex + Figma 生成 Objective‑C (UIKit) 完整工作流
c语言·开发语言·figma