#include <algorithm> #include <cctype> #include <cmath> #include <cstring> #include <iostream> #include <string> #include <vector> using namespace std; int main() { int xx[4] = {0, 1, 0, -1}; int yy[4] = {1, 0, -1, 0}; int cnt = 3; int a, b; cin >> a >> b; char arr[a + 2][b + 2]; memset(arr, 0, sizeof(arr)); int x = 1; int y = 0; for (int i = 0; i < a + 2; i++) arr[i][0] = arr[i][b + 1] = 1; for (int i = 0; i < b + 2; i++) arr[0][i] = arr[a + 1][i] = 1; for (int i = 0; i < a * b; i++) { if (arr[x + xx[cnt]][y + yy[cnt]] != 0) cnt = (cnt + 1) % 4; x += xx[cnt]; y += yy[cnt]; arr[x][y] = 'A' + (i % 26); } for (int i = 1; i < a + 1; i++) { for (int j = 1; j < b + 1; j++) { if (j != 0) cout << " "; cout << arr[i][j]; } cout << endl; } } |
Double click to view unformatted code.