3 solutions
-
0
代码很好懂
#include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<algorithm> #include<vector> #include<string> #include<map> #include <climits> using namespace std; int num[205][205]; bool numi[205][205]; int main(void) { int a, b; cin >> a >> b; int k = a * b; for(int i=0;i<a;i++) for (int t = 0; t < b; t++) { cin >> num[i][t]; numi[i][t] = true; } int x = 0, y = 0; while (k) { for (int i = y; i < a; i++) { if (!numi[i][x]) break; y = i; k--; numi[i][x] = false; k != 0 ? cout << num[i][x] << " " : cout << num[i][x]; } if (!k) break; x++; for (int i = x; i < b; i++) { if (!numi[y][i]) break; x = i; k--; numi[y][i] = false; k != 0 ? cout << num[y][i] << " " : cout << num[y][i]; } if (!k) break; y--; for (int i = y; i >= 0; i--) { if (!numi[i][x]) break; y = i; k--; numi[i][x] = false; k != 0 ? cout << num[i][x] << " " : cout << num[i][x]; } if (!k) break; x--; for (int i = x; i >= 0; i--) { if (!numi[y][i]) break; x = i; k--; numi[y][i] = false; k != 0 ? cout << num[y][i] << " " : cout << num[y][i]; } if (!k) break; y++; } return 0; }
Information
- ID
- 1176
- Time
- 1000ms
- Memory
- 512MiB
- Difficulty
- 8
- Tags
- # Submissions
- 39
- Accepted
- 8
- Uploaded By