top1编程
← 返回题目
题解

【入门】奇特的三角

1 条题解

  • 0
    @ 2026-7-29 0:15:22
    #include <iostream>
    using namespace std;
    
    int main() {
        int n;
        cin >> n;
    
        for (int i = 1; i <= n; ++i) {
            // 左侧的 *
            for (int j = 1; j <= n - i; ++j) {
                cout << "*";
            }
            // 中间的 @
            for (int j = 1; j <= 2 * i - 1; ++j) {
                cout << "@";
            }
            // 右侧的 *
            for (int j = 1; j <= n - i; ++j) {
                cout << "*";
            }
            cout << endl;
        }
    
        return 0;
    }
    
    • 1