#include #include using namespace std; void printmatrix(char * m, int n) { for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { printf("%c", m[i * n + j]); } printf("\n"); } } void maketable(char * cmds, int cmds_cnt, char * table) { char transforms[128][128]; transforms['<']['<'] = 'v'; transforms['<']['>'] = '^'; transforms['<']['-'] = '<'; transforms['<']['|'] = '>'; transforms['<'][92] = '^'; transforms['<']['/'] = 'v'; transforms['>']['<'] = '^'; transforms['>']['>'] = 'v'; transforms['>']['-'] = '>'; transforms['>']['|'] = '<'; transforms['>'][92] = 'v'; transforms['>']['/'] = '^'; transforms['^']['<'] = '<'; transforms['^']['>'] = '>'; transforms['^']['-'] = 'v'; transforms['^']['|'] = '^'; transforms['^'][92 ] = '<'; transforms['^']['/'] = '>'; transforms['v']['<'] = '>'; transforms['v']['>'] = '<'; transforms['v']['-'] = '^'; transforms['v']['|'] = 'v'; transforms['v'][92 ] = '>'; transforms['v']['/'] = '<'; transforms['o']['<'] = 'o'; transforms['o']['>'] = 'o'; transforms['o']['-'] = 'o'; transforms['o']['|'] = 'o'; transforms['o'][92 ] = 'o'; transforms['o']['/'] = 'o'; transforms['x']['<'] = 'x'; transforms['x']['>'] = 'x'; transforms['x']['-'] = 'x'; transforms['x']['|'] = 'x'; transforms['x'][92 ] = 'x'; transforms['x']['/'] = 'x'; transforms['|']['<'] = '-'; transforms['|']['>'] = '-'; transforms['|']['-'] = '|'; transforms['|']['|'] = '|'; transforms['|'][92 ] = '-'; transforms['|']['/'] = '-'; transforms['-']['<'] = '|'; transforms['-']['>'] = '|'; transforms['-']['-'] = '-'; transforms['-']['|'] = '-'; transforms['-'][92 ] = '|'; transforms['-']['/'] = '|'; transforms['/']['<'] = 92; transforms['/']['>'] = 92; transforms['/']['-'] = 92; transforms['/']['|'] = 92; transforms['/'][92 ] = '/'; transforms['/']['/'] = '/'; transforms[92]['<'] = '/'; transforms[92]['>'] = '/'; transforms[92]['-'] = '/'; transforms[92]['|'] = '/'; transforms[92][92 ] = 92; transforms[92]['/'] = 92; table['<'] = '<'; table['>'] = '>'; table['^'] = '^'; table['v'] = 'v'; table['o'] = 'o'; table['x'] = 'x'; table['|'] = '|'; table['-'] = '-'; table['/'] = '/'; table[92] = 92; for(int i = 0; i < cmds_cnt; i++) { char cmd = cmds[i]; table['<'] = transforms[table['<']][cmd]; table['>'] = transforms[table['>']][cmd]; table['^'] = transforms[table['^']][cmd]; table['v'] = transforms[table['v']][cmd]; table['o'] = transforms[table['o']][cmd]; table['x'] = transforms[table['x']][cmd]; table['|'] = transforms[table['|']][cmd]; table['-'] = transforms[table['-']][cmd]; table['/'] = transforms[table['/']][cmd]; table[92] = transforms[table[92]][cmd]; } } int sign(int x) { if(x > 0) return 1; if(x < 0) return -1; return 0; } void flipcoords(int x, int y, int * ox, int * oy, char cmd, int n) { if(cmd == '<') { *oy = x; // sloupec je radek *ox = n - 1 - y; // radek je n - 1 - sloupec } else if(cmd == '>') { *oy = n - 1 - x; // sloupec je n - 1 - radek *ox = y; // radek je sloupec } else if(cmd == '-') { *oy = y; // sloupec zustane *ox = n - 1 - x; // radek je n - 1 - radek } else if(cmd == '|') { *oy = n - 1 - y; // sloupec je n - 1 - sloupec *ox = x; // radek zustane } else if(cmd == '/') { *oy = n - 1 - x; // sloupec je n - 1 - radek *ox = n - 1 - y; // radek je n - 1 - sloupec } else if(cmd == 92) { *oy = x; // sloupec radek *ox = y; // radek sloupec } } int main(int argc, char ** argv) { int n; while(scanf("%d", &n) == 1) { char * m1 = new char[n*n]; char * m2 = new char[n*n]; char * cmds = new char[1024 * 1024]; char table[128]; char c; int cmds_cnt = 0; // nacitani for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { scanf(" %c", &c); m1[i * n + j] = c; } } while(scanf("%c", &c) == 1) { if(!cmds_cnt && c == '\n') continue; // preskocit uvodni newline if(c == '\n') break; else if(c == ' ') continue; cmds[cmds_cnt++] = c; } maketable(cmds, cmds_cnt, table); /*printf("%c %c %c %c %c %c %c %c %c %c\n", table['<'], table['>'], table['^'], table['v'], table['o'], table['x'], table['|'], table['-'], table['/'], table[92]);*/ // transformuju pozice for(int shell = 0; shell < (n+1) / 2; shell++) { // transformuju levy horni roh int x1 = shell, y1 = shell; for(int cmd = 0; cmd < cmds_cnt; cmd++) { flipcoords(x1, y1, &x1, &y1, cmds[cmd], n); } // transformuju pravy horni roh int x2 = shell, y2 = n - 1 - shell; for(int cmd = 0; cmd < cmds_cnt; cmd++) { flipcoords(x2, y2, &x2, &y2, cmds[cmd], n); } // transformuju levy dolni roh int x3 = n - 1 - shell, y3 = shell; for(int cmd = 0; cmd < cmds_cnt; cmd++) { flipcoords(x3, y3, &x3, &y3, cmds[cmd], n); } // transformuju pravy dolni roh int x4 = n - 1 - shell, y4 = n - 1 - shell; for(int cmd = 0; cmd < cmds_cnt; cmd++) { flipcoords(x4, y4, &x4, &y4, cmds[cmd], n); } int len = n - shell * 2; for(int i = 0; i < len; i++) { // vyplnim horni radu m2[(x1 + sign(x2 - x1) * i) * n + (y1 + sign(y2 - y1) * i)] = m1[(shell) * n + (shell + i)]; // vyplnim pravou radu m2[(x2 + sign(x4 - x2) * i) * n + (y2 + sign(y4 - y2) * i)] = m1[(shell + i) * n + (n - 1 - shell)]; // vyplnim dolni radu m2[(x3 + sign(x4 - x3) * i) * n + (y3 + sign(y4 - y3) * i)] = m1[(n - 1 - shell) * n + (shell + i)]; // vyplnim levou radu m2[(x1 + sign(x3 - x1) * i) * n + (y1 + sign(y3 - y1) * i)] = m1[(shell + i) * n + (shell)]; } } // pretocim znaky for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { m2[i * n + j] = table[m2[i * n + j]]; } } printmatrix(m2, n); delete [] m1; delete [] m2; delete [] cmds; } return 0; }