Paste: 1.第一题参考

Author: R2D2
Mode: c++
Date: Mon, 15 Nov 2021 06:22:30
Plain Text |
#include <iostream>

int main() {
    int n;
    std::cin >> n;
    for (int i = 0; i < n; ++i) {
        if (i == 0) {
            for (int j = 0; j < n; ++j) {
                std::cout << "* ";
            }
            std::cout << std::endl;
        } else if (i != n - 1) {
            for (int k = 0; k < 2 * i; ++k) {
                std::cout << " ";
            }
            for (int j = 0; j < n; ++j) {
                if (j == 0) {
                    std::cout << "* ";
                } else if (j != n - 1) {
                    std::cout << "  ";
                } else {
                    std::cout << "* " << std::endl;
                }
            }
        } else {
            for (int k = 0; k < 2 * i; ++k) {
                std::cout << " ";
            }
            for (int j = 0; j < n; ++j) {
                std::cout << "* ";
            }
            std::cout << std::endl;
        }
    }
    return 0;
}

New Annotation

Summary:
Author:
Mode:
Body: