题解 | 输出梯形
#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")
查看12道真题和解析