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

    你可能感兴趣的文章
    org.apache.ibatis.type.TypeException: Could not resolve type alias 'xxxx'异常
    查看>>
    org.apache.poi.hssf.util.Region
    查看>>
    org.apache.xmlbeans.XmlOptions.setEntityExpansionLimit(I)Lorg/apache/xmlbeans/XmlOptions;
    查看>>
    org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /
    查看>>
    org.hibernate.HibernateException: Unable to get the default Bean Validation factory
    查看>>
    org.hibernate.ObjectNotFoundException: No row with the given identifier exists:
    查看>>
    org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
    查看>>
    org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
    查看>>
    org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size exceeded
    查看>>
    org.tinygroup.serviceprocessor-服务处理器
    查看>>
    org/eclipse/jetty/server/Connector : Unsupported major.minor version 52.0
    查看>>
    org/hibernate/validator/internal/engine
    查看>>
    SQL-36 创建一个actor_name表,将actor表中的所有first_name以及last_name导入改表。
    查看>>
    ORM sqlachemy学习
    查看>>
    Ormlite数据库
    查看>>
    orm总结
    查看>>
    os.path.join、dirname、splitext、split、makedirs、getcwd、listdir、sep等的用法
    查看>>
    os.system 在 Python 中不起作用
    查看>>
    OSCACHE介绍
    查看>>
    SQL--合计函数(Aggregate functions):avg,count,first,last,max,min,sum
    查看>>