题解 | 输出梯形

#include <iostream>
using namespace std;

int main() {
    int h;
    while (cin >> h) { // 注意 while 处理多个 case
        //提前获知行列
        int c = h + (h - 1) * 2;
        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < c; ++j) {
                if (j >= c - h - 2 * i) {
                    cout << "*";
                } else {
                    cout << "  ";//两个空格顶一个*号
                }
            }
            cout << endl;
        }
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

牛客52811839...:有的hr就是这样啊,很正常。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务