Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
119649 | 胡海峰老师 | 打印数字图形 | C++ | Accepted | 3 MS | 276 KB | 1238 | 2025-05-18 10:30:04 |
#include <iostream> using namespace std; int main() { int n; // 循环处理多组输入 while (cin >> n) { // 处理上半部分(包括中间行) for (int i = 1; i <= n; i++) { // 打印前置空格 for (int space = 0; space < n - i; space++) { cout << " "; } // 打印递增序列 for (int j = 1; j <= i; j++) { cout << j; } // 打印递减序列(从i-1到1) for (int j = i - 1; j >= 1; j--) { cout << j; } cout << endl; // 换行 } // 处理下半部分(不包括中间行) for (int i = n - 1; i >= 1; i--) { // 打印前置空格 for (int space = 0; space < n - i; space++) { cout << " "; } // 打印递增序列 for (int j = 1; j <= i; j++) { cout << j; } // 打印递减序列 for (int j = i - 1; j >= 1; j--) { cout << j; } cout << endl; // 换行 } } return 0; }