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

相关推荐
yaoh.wang5 分钟前
力扣(LeetCode) 100: 相同的树 - 解法思路
python·程序人生·算法·leetcode·面试·职场和发展·跳槽
SadSunset7 分钟前
力扣题目142. 环形链表 II的解法分享,附图解
算法·leetcode·链表
月光在发光20 分钟前
多态(虚函数核心作用原理)--C++学习(0)
c++·学习
Sunsets_Red27 分钟前
2025 FZYZ夏令营游记
java·c语言·c++·python·算法·c#
自由生长202442 分钟前
从流式系统中思考-C++生态和Java生态的区别
java·c++
iAkuya1 小时前
(leetcode)力扣100 19螺旋矩阵(方向数组/边界把控)
算法·leetcode·矩阵
培培说证1 小时前
2026大专Java开发工程师,考什么证加分?
java·开发语言·python
爱编程的小吴1 小时前
【力扣练习题】热题100道【哈希】 最长连续序列
算法·leetcode·职场和发展
qq_336313931 小时前
java基础-方法引用
java·开发语言·算法
总是学不会.1 小时前
【JUC编程】一、线程的基础概念
java·开发语言·jvm