1 条题解

  • 0
    @ 2024-2-1 12:00:16
    #include <iostream>
    using namespace std;
    
    void printSquare(int size) {
        for (int i = 0; i < size; ++i) {
            for (int j = 0; j < size; ++j) {
                cout << "*";
            }
            cout << "\n";
        }
    }
    
    void printDiamond(int size) {
        // 打印上半部分
        for (int i = 1; i <= size; ++i) {
            cout << string(size - i, ' ') << string(2 * i - 1, '*') << "\n";
        }
        // 打印下半部分
        for (int i = size - 1; i > 0; --i) {
            cout << string(size - i, ' ') << string(2 * i - 1, '*') << "\n";
        }
    }
    
    int main() {
        char shape;
        int size;
    
        // 读取图形类型和大小
        cin >> shape >> size;
    
        // 根据输入打印图形
        if (shape == 'Z') {
            printSquare(size);
        }  
        if (shape == 'L') {
            printDiamond(size);
        } 
    
        return 0;
    }
    
    • 1

    信息

    ID
    144
    时间
    1000ms
    内存
    64MiB
    难度
    10
    标签
    递交数
    3
    已通过
    2
    上传者