2 条题解
-
2
e······
#include <iostream> using namespace std; int n, t; void f(int i) { for (int j = 0 ; j < i ; j++) cout << ' '; cout << 'X'; for (int j = 0 ; j < n - i * 2 - 2 ; j++) cout << ' '; cout << 'X' << endl ; } int main() { cin >> n ; for (int i = 0 ; i < n / 2 ; i++) f(i); for (int i = 0 ; i < n / 2 ; i++) cout << ' '; cout << 'X' << endl; for (int i = n / 2 - 1; i >= 0 ; i--) f(i); return 0; }
-
1
有点麻烦,但不多,来看一下本题的注意事项:
- 中间那一行要注意,只有一个“X”,不要打成了两个“X”
- 先掌握住空格的打印次数的规律,再确定循环变量的范围,千万不要急着下手
OK,话不多说,上代码!
已AC,请放心食用
#include <iostream> using namespace std; int main() { int n; cin >> n; for (int i = 1; i <= n / 2; i++) { for (int j = 1; j <= i - 1; j++) { cout << " "; } cout << "X"; for (int j = 1; j <= n - i * 2; j++) { cout << " "; } cout << "X" << endl; } for (int i = 1; i <= n / 2; i++) { cout << " "; } cout << "X" << endl; for (int i = 1; i <= n / 2; i++) { for (int j = 1; j <= n / 2 - i; j++) { cout << " "; } cout << "X"; for (int j = 1; j <= i * 2 - 1; j++) { cout << " "; } cout << "X" << endl; } return 0; }
养成好习惯,看后点个赞😎!
大家连成心,赞赞变成金😁!
点个赞吧😄~
- 1
信息
- ID
- 239
- 时间
- 1000ms
- 内存
- 16MiB
- 难度
- 5
- 标签
- 递交数
- 112
- 已通过
- 43
- 上传者