#include #include

int main() { int n; std::cin >> n;

// 初始化方阵
int matrix[100][100] = {0};

// 填充对角线和右下方
for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
        matrix[i][j] = j - i + 1;
    }
}

// 输出方阵
for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
        if (matrix[i][j] == 0) {
            std::cout << std::setw(5) << "";
        } else {
            std::cout << std::setw(5) << matrix[i][j];
        }
    }
    std::cout << std::endl;
}

return 0;

}

【GESP三级】有趣的数字图形III暂无标签时间限制:CC++ 1000MS其他语言 2000MS内存限制:CC++ 16MB其他语言 32MB难度:中等出题人:描述读入一个整数nn100输出一个nn的方阵。 对角线是1对角线向右下逐渐递增左上为空格每个数场宽为5。输入描述一个整数n输出描述nn的方阵用例输入 1 4用例输出 1 1

原文地址: https://www.cveoy.top/t/topic/jgl7 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录