题目描述:
输入一个高度h,输出一个高为h,上底边为h的梯形。
输入:
一个整数h(1<=h<=1000)。
输出:
h所对应的梯形。
样例输入:
4
样例输出:
**** ****** ******** **********
# include<iostream>
# include<string>
# include<vector>
# include<algorithm>
# include<cmath>
# include<cstdio>
# include<map>
using namespace std;
int main() {
char a[1001][1001] = {' '}; //为了方便 1-10这样计算
int h;
cin >> h;
int blowNumber = h + (h - 1) * 2; // 底边*的个数
int firstStarIndex = blowNumber - h + 1; //第一行 *的起始下标 // 10 - 4 = 6 --> 7-8-9-10
for(int i = 1; i <= h; i++) {
for (int j = firstStarIndex; j <= blowNumber; j++) {
a[i][j] = '*';
}
if (firstStarIndex >= 3) {
firstStarIndex -= 2;
}
}
for(int i = 1; i <= h; i++) {
for (int j = 1; j <= blowNumber; j++) {
cout << a[i][j];
}
cout << endl;
}
}
来源:CSDN
作者:bijingrui
链接:https://blog.csdn.net/bijingrui/article/details/103949713