1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | #include<iostream> #include<string> using namespace std; int main() { string sarr[25][25]; int f[8][2] = { {-1,-1},{-1,0},{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1} }; int N, index, x, y; cin >> N; cin >> index; for (int i = 0; i < 25; i++) for (int j = 0; j < 25; j++) sarr[i][j] = ""; for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { sarr[i][j] = 'A' + i - 1; sarr[i][j] += j + '0'; } } x = index / N + 1; y = index % N + 1; for (int i = 0; i < 8; i++) { if (sarr[x + f[i][0]][y + f[i][1]] != "") cout << (x + f[i][0] - 1) * N + (y + f[i][1]) - 1 << " "; else cout << "-1 "; } cout << endl; for (int i = 0; i < 8; i++) { if (sarr[x + f[i][0]][y + f[i][1]] != "") cout << sarr[x + f[i][0]][y + f[i][1]] << " "; else cout << "-1 "; } cout << endl; return 0; } |
2019年9月4日 星期三
itsa [C_AR031-中]一維矩陣表示二維平面空間
訂閱:
文章 (Atom)