博客
关于我
Codeup——577 | 问题 C: 等腰梯形
阅读量:114 次
发布时间:2019-02-26

本文共 705 字,大约阅读时间需要 2 分钟。

为了解决这个问题,我们需要根据给定的高度h生成一个等腰梯形。等腰梯形的上底边长为h,下底边长为2h,中间部分由两部分组成,每侧有h个星号,中间有h个星号。

方法思路

  • 问题分析:我们需要生成一个等腰梯形,给定高度h,上底边长为h,下底边长为2h,中间部分由两部分组成,每侧有h个星号,中间有h个星号。
  • 图形结构:上底边有h个星号,中间部分有2h个星号,下底边有2h个星号。
  • 代码实现:读取输入值m,处理每个测试用例,生成相应的等腰梯形并输出。
  • 解决代码

    #include 
    using namespace std;int main() { int m, h; cin >> m; for (int i = 0; i < m; ++i) { cin >> h; string top(h, '*'); string middle(2 * h, '*'); string bottom(2 * h, '*'); cout << top << endl; cout << middle << endl; cout << bottom << endl; } return 0;}

    代码解释

  • 读取输入:首先读取输入值m,表示测试用例的数量。
  • 处理每个测试用例:对于每个h,生成上底边、中间部分和下底边。
  • 生成图形:上底边由h个星号组成,中间部分由2h个星号组成,下底边由2h个星号组成。
  • 输出结果:将生成的图形按行输出。
  • 这个方法确保了每个等腰梯形的结构正确,满足题目的要求。

    转载地址:http://hufk.baihongyu.com/

    你可能感兴趣的文章
    prometheus常用exporter下载地址大全
    查看>>
    Prometheus快速搭建与监控Linux系统实战
    查看>>
    prometheus报警与恢复告警的格式
    查看>>
    Pytorch中安装 torch_geometric 详细图文操作(全)
    查看>>
    prometheus监控docker容器实战
    查看>>
    Prometheus监控k8s集群使用邮箱和微信告警!
    查看>>
    Prometheus监控mysq数据库实战
    查看>>
    prometheus监控nginx实战
    查看>>
    Prometheus监控redis数据库实战
    查看>>
    Prometheus监控教程:使用Grafana展示主机基本信息
    查看>>
    pytorch中如何使用预训练词向量
    查看>>
    Prometheus监控教程:使用PromQL查询监控数据(上篇)
    查看>>
    Prometheus监控教程:使用PromQL查询监控数据(下篇)
    查看>>
    Pytorch中关于forward函数的理解与用法
    查看>>
    Prometheus监控教程:安装部署
    查看>>
    Prometheus监控教程:配置介绍
    查看>>
    Pytorch中tqdm进度条的使用
    查看>>
    Prometheus(2):SpringBoot 2.X集成Prometheus
    查看>>
    Promise 原理解析与实现(遵循Promise/A+规范)
    查看>>