Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
113282 | 彭士宝 | 打印菱形 | C++ | Accepted | 2 MS | 276 KB | 900 | 2025-03-15 16:29:53 |
#include <iostream> #include <string> using namespace std; // 打印单行菱形图案 void printLine(int spaces, int stars) { string line(spaces, ' '); // 创建空格部分 line += string(stars, '*'); // 添加星号部分 cout << line << endl; // 输出当前行 } int main() { int n; cin >> n; // 输入正整数n // 打印菱形的上半部分(包括中间一行) for (int i = 1; i <= n; ++i) { int spaces = n - i; // 每行前面的空格数 int stars = 2 * i - 1; // 每行的星号数 printLine(spaces, stars); } // 打印菱形的下半部分 for (int i = n - 1; i >= 1; --i) { int spaces = n - i; // 每行前面的空格数 int stars = 2 * i - 1; // 每行的星号数 printLine(spaces, stars); } return 0; }