博客
关于我
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/

    你可能感兴趣的文章
    poj 3083 Children of the Candy Corn
    查看>>
    POJ 3083 Children of the Candy Corn 解题报告
    查看>>
    POJ 3253 Fence Repair C++ STL multiset 可解 (同51nod 1117 聪明的木匠)
    查看>>
    Qt笔记——控件总结
    查看>>
    poj 3262 Protecting the Flowers 贪心
    查看>>
    poj 3264(简单线段树)
    查看>>
    Qt笔记——布局管理三件套分割窗口、停靠窗口和堆栈窗口
    查看>>
    poj 3277 线段树
    查看>>
    POJ 3349 Snowflake Snow Snowflakes
    查看>>
    POJ 3411 DFS
    查看>>
    poj 3422 Kaka's Matrix Travels (费用流 + 拆点)
    查看>>
    Qt笔记——官方文档全局定义(二)Functions函数
    查看>>
    POJ 3468 A Simple Problem with Integers
    查看>>
    poj 3468 A Simple Problem with Integers 降维线段树
    查看>>
    poj 3468 A Simple Problem with Integers(线段树 插线问线)
    查看>>
    poj 3485 区间选点
    查看>>
    poj 3518 Prime Gap
    查看>>
    poj 3539 Elevator——同余类bfs
    查看>>
    Qt笔记——官方文档全局定义(三)Macros宏
    查看>>
    poj 3628 Bookshelf 2
    查看>>