NOI-1.1-08-字符三角形
08:字符三角形
- 总时间限制:
- 1000ms
- 内存限制:
- 65536kB
- 描述
-
给定一个字符,用它构造一个底边长5个字符,高3个字符的等腰字符三角形。
- 输入
- 输入只有一行, 包含一个字符。
- 输出
- 该字符构成的等腰三角形,底边长5个字符,高3个字符。
- 样例输入
-
*
- 样例输出
-
* *** *****
#include <iostream> #include <algorithm> #include <stdio.h> #include <string> #include <ctype.h> using namespace std; int main() { char a; scanf("%c", &a); for(int i = 1; i <=3; i++) { int num = 2*i-1; int kong = (5-num)/2; for(int j = 1; j <= kong; j++) cout << " "; for(int j = 1; j <= num; j++) cout << a; for(int j = 1; j <= kong; j++) cout << " "; cout << endl; } return 0; }
采用了麻烦一点的方法,为了更有拓展性