提交时间:2026-05-22 15:07:57
运行 ID: 89069
#include <iostream> using namespace std; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { if (i == 0 || i == n - 1) { // 第一行和最后一行:全是星号 for (int j = 0; j < n; j++) { cout << "*"; } } else { // 中间行:前面输出空格,最后输出一个星号,形成斜线 for (int j = 0; j < n - 1 - i; j++) { cout << " "; } cout << "*"; } cout << endl; } return 0; }