Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
87551 | Kevin | 二维数组输出(4) | C++ | Accepted | 1 MS | 240 KB | 576 | 2024-08-10 16:18:44 |
#include<stdio.h> int main() { int arr[100][100] = { 0 }; int i = 0, j = 0, count = 0, k = 1; int N = 0; scanf("%d", &N); int startX = 0, startY = N-1; while (count < N) { if (count % 2 == 0) { for (i = startX; i < N; i++) { arr[count][i] = k++; } } else { for (j = startY; j >= 0; j--) { arr[count][j] = k++; } } count++; } for (i = 0; i < N; i++) { for (j = 0; j < N; j++) { if (j == N - 1) { printf("%d\n", arr[i][j]); } else { printf("%d ", arr[i][j]); } } } return 0; }