Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
65775 zyqll 方阵填数 C++ Wrong Answer 1 MS 268 KB 1045 2024-02-10 02:34:46

Tests(0/3):


Code:

#include <iostream> #include <vector> using namespace std; int main() { int n; cin >> n; int array[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { array[i][j] = -1; } } int I = 0; int J = n - 1; int count = 1; int stepI = 1; int stepJ = 0; while (1) { array[I][J] = count++; I += stepI; J += stepJ; if (array[I][J] != -1) { I -= stepI; J -= stepJ; if (stepI == 0) { stepI = stepJ; stepJ = 0; } else { stepJ = -stepI; stepI = 0; } I += stepI; J += stepJ; if (array[I][J] != -1) { break; } } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cout << array[i][j] << ","; } cout << endl; } return 0; }


Run Info:

------Input------
10
------Answer-----
28 29 30 31 32 33 34 35 36 1 27 58 59 60 61 62 63 64 37 2 26 57 80 81 82 83 84 65 38 3 25 56 79 94 95 96 85 66 39 4 24 55 78 93 100 97 86 67 40 5 23 54 77 92 99 98 87 68 41 6 22 53 76 91 90 89 88 69 42 7 21 52 75 74 73 72 71 70 43 8 20 51 50 49 48 47 46 45 44 9 19 18 17 16 15 14 13 12 11 10
------Your output-----
28,29,30,31,32,33,34,35,36,1, 27,58,59,60,61,62,63,64,37,2, 26,57,80,81,82,83,84,65,38,3, 25,56,79,94,95,96,85,66,39,4, 24,55,78,93,100,97,86,67,40,5, 23,54,77,92,99,98,87,68,41,6, 22,53,76,91,90,89,88,69,42,7, 21,52,75,74,73,72,71,70,43,8, 20,51,50,49,48,47,46,45,44,9, 19,18,17,16,15,14,13,12,11,10,