/* * File: display.cpp * Author: cteam033 * * Created on October 22, 2016, 11:27 AM */ #include #include #include using namespace std; void turn_left(char **matrix_to, char **matrix_from, int count) { for (int i = 0; i <= count; ++i) { for (int j = 0; j <= count; ++j) { switch (matrix_from[i][j]) { case '<': matrix_to[count - j][i] = 'v'; break; case 'v': matrix_to[count - j][i] = '>'; break; case '>': matrix_to[count - j][i] = '^'; break; case '^': matrix_to[count - j][i] = '<'; break; case '-': matrix_to[count - j][i] = '|'; break; case '|': matrix_to[count - j][i] = '-'; break; case '/': matrix_to[count - j][i] = '\\'; break; case '\\': matrix_to[count - j][i] = '/'; break; default: matrix_to[count - j][i] = matrix_from[i][j]; } } } } void turn_right(char **matrix_to, char **matrix_from, int count) { for (int i = 0; i <= count; ++i) { for (int j = 0; j <= count; ++j) { switch (matrix_from[i][j]) { case '<': matrix_to[j][count - i] = '^'; break; case 'v': matrix_to[j][count - i] = '<'; break; case '>': matrix_to[j][count - i] = 'v'; break; case '^': matrix_to[j][count - i] = '>'; break; case '-': matrix_to[j][count - i] = '|'; break; case '|': matrix_to[j][count - i] = '-'; break; case '/': matrix_to[j][count - i] = '\\'; break; case '\\': matrix_to[j][count - i] = '/'; break; default: matrix_to[j][count - i] = matrix_from[i][j]; } } } } void vertical_mirror(char **matrix_to, char **matrix_from, int count) { for (int i = 0; i <= count; ++i) { for (int j = 0; j <= count; ++j) { switch (matrix_from[i][j]) { case '<': matrix_to[i][count - j] = '>'; break; case '>': matrix_to[i][count - j] = '<'; break; case '/': matrix_to[i][count - j] = '\\'; break; case '\\': matrix_to[i][count - j] = '/'; break; default: matrix_to[i][count - j] = matrix_from[i][j]; } } } } void horizont_mirror(char **matrix_to, char **matrix_from, int count) { for (int i = 0; i <= count; ++i) { for (int j = 0; j <= count; ++j) { switch (matrix_from[i][j]) { case 'v': matrix_to[count - i][j] = '^'; break; case '^': matrix_to[count - i][j] = 'v'; break; case '/': matrix_to[count - i][j] = '\\'; break; case '\\': matrix_to[count - i][j] = '/'; break; default: matrix_to[count - i][j] = matrix_from[i][j]; } } } } void copy_matrix(char **matrix_to, char **matrix_from, int count) { for (int i = 0; i < count; ++i) { for (int j = 0; j < count; ++j) { matrix_to[i][j] = matrix_from[i][j]; } } } void read_matrix(char **matrix, int count) { for (int i = 0; i < count; ++i) for (int j = 0; j < count; ++j) cin >> matrix[i][j]; } void print_matrix(char **matrix, int count) { for (int i = 0; i < count; ++i) { for (int j = 0; j < count; ++j) cout << matrix[i][j]; cout << endl; } } int main(int argc, char** argv) { int count; while (cin >> count) { char **matrix_to = new char*[count]; for (int i = 0; i < count; ++i) matrix_to[i] = new char[count]; char **matrix_from = new char*[count]; for (int i = 0; i < count; ++i) matrix_from[i] = new char[count]; read_matrix(matrix_to, count); char command; bool dir = false; scanf("%c", &command); while (scanf("%c", &command) == 1) { if (command == ' ') continue; else if (command == '\n') break; switch (command) { case '<': if (dir) turn_left(matrix_to, matrix_from, count - 1); else turn_left(matrix_from, matrix_to, count - 1); break; case '>': if (dir) turn_right(matrix_to, matrix_from, count - 1); else turn_right(matrix_from, matrix_to, count - 1); break; case '|': if (dir) vertical_mirror(matrix_to, matrix_from, count - 1); else { vertical_mirror(matrix_from, matrix_to, count - 1); } break; case '-': if (dir) horizont_mirror(matrix_to, matrix_from, count - 1); else { horizont_mirror(matrix_from, matrix_to, count - 1); } break; case '/': if (dir) { turn_right(matrix_to, matrix_from, count - 1); horizont_mirror(matrix_from, matrix_to, count - 1); } else { turn_right(matrix_from, matrix_to, count - 1); horizont_mirror(matrix_to, matrix_from, count - 1); } dir = !dir; break; case '\\': if (dir) { turn_left(matrix_to, matrix_from, count - 1); horizont_mirror(matrix_from, matrix_to, count - 1); } else { turn_left(matrix_from, matrix_to, count - 1); horizont_mirror(matrix_to, matrix_from, count - 1); } dir = !dir; break; } if (dir) dir = false; else dir = true; } if (!dir) print_matrix(matrix_to, count); else print_matrix(matrix_from, count); for (int i = 0; i < count; ++i){ delete []matrix_from[i]; delete []matrix_to[i]; } delete [] matrix_from; delete [] matrix_to; } return 0; }