// // File: grille.cc // Author: cteam03 // // Created on November 13, 2011, 11:30 AM // #include #include #include #include #include using namespace std; struct pont { int x, y; pont(int a, int b) { x = a; y = b; } }; bool compare(pont *lhs, pont *rhs) { if (lhs->x > rhs->x) return true; else if (lhs->x < rhs->x) return false; else { if (lhs->y < rhs->y) return true; else if (lhs->y >= rhs->y) return false; } return false; }; // // // int main(int argc, char** argv) { int N; scanf("%d", &N); getchar(); while (N != 0) { vector lista[4]; for (int i = 0; i < N; i++) { char line[1001]; scanf("%s", line); for (int j = 0; j < N; j++) { if (line[j] == '0') { if (N % 2) { int x = -i + N / 2; int y = j - N / 2; lista[0].push_back(new pont(x, y)); lista[1].push_back(new pont(-y, x)); lista[2].push_back(new pont(-x, -y)); lista[3].push_back(new pont(y, -x)); } else { int x = -i + N / 2; int y = j - N / 2; if (x <= 0) x--; if (y >= 0) y++; lista[0].push_back(new pont(x, y)); lista[1].push_back(new pont(-y, x)); lista[2].push_back(new pont(-x, -y)); lista[3].push_back(new pont(y, -x)); } } } } char tomb[1001][1001]; for (int i = 0; i < N; i++) { scanf("%s", tomb[i]); } sort(lista[0].begin(), lista[0].end(), compare); sort(lista[1].begin(), lista[1].end(), compare); sort(lista[2].begin(), lista[2].end(), compare); sort(lista[3].begin(), lista[3].end(), compare); for (int i = 0; i < 4; i++) { for (int j = 0; j < lista[i].size(); j++) { if (N % 2 == 0) { int x = -lista[i][j]->x + N / 2; int y = lista[i][j]->y + N / 2; if (lista[i][j]->x < 0) x--; if (lista[i][j]->y > 0) y--; printf("%c", tomb[x][y]); } else { int x = -lista[i][j]->x + N / 2; int y = lista[i][j]->y + N / 2; printf("%c", tomb[x][y]); } } } printf("\n"); scanf("%d", &N); getchar(); } return 0; }