Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Codeforces Gym S02E04 problem D
- sakib_rulez
- */
- #include <stdio.h>
- #include <iostream>
- using namespace std;
- int sx,sy,dx,dy,n;
- bool inv;
- char g[1005][1005],a[5][5];
- void calc()
- {
- if(sx==1) dx=1;
- else dx=-1;
- if(sy==1) dy=1;
- else dy=-1;
- }
- void rotate()
- {
- // inv means present row orientation is inverted to the columns
- // of original grid and vice versa
- inv^=1;
- if(sx==1 && sy==1) sx=n;
- else if(sx==n && sy==1) sy=n;
- else if(sx==n && sy==n) sx=1;
- else if(sx==1 && sy==n) sy=1;
- calc();
- }
- void horizontal()
- {
- sx=n+1-sx;
- calc();
- }
- void vertical()
- {
- sy=n+1-sy;
- calc();
- }
- void replace(int bx,int by)
- {
- int i,j;
- for(i=0;i<3;i++)
- {
- for(j=0;j<3;j++)
- {
- if(!inv) g[sx+dx*(i+bx-1)][sy+dy*(j+by-1)]=a[i][j];
- else g[sy+dy*(j+by-1)][sx+dx*(i+bx-1)]=a[i][j];
- }
- }
- }
- void show()
- {
- int i,j;
- for(i=0;i<n;i++)
- {
- for(j=0;j<n;j++)
- {
- if(!inv) printf("%c",g[sx+dx*i][sy+dy*j]);
- else
- printf("%c",g[sy+dy*j][sx+dx*i]);
- }
- printf("\n");
- }
- }
- int main()
- {
- int i,j,k,q,bx,by;
- char str[20];
- scanf("%d %d",&n,&q);
- for(i=1;i<=n;i++) for(j=1;j<=n;j++) g[i][j]='.';
- sx=sy=dx=dy=1;
- for(i=0;i<q;i++)
- {
- scanf("%s",str);
- //Rotate
- if(str[1]=='O')
- {
- scanf("%s",str);
- if(str[1]=='C') rotate(); //Rotate CounterClockWise
- else
- {
- //Rotate Clockwise = Roatete Counterclockwise 3 times
- rotate();
- rotate();
- rotate();
- }
- }
- //MIRROR
- else if(str[1]=='I')
- {
- scanf("%s",str);
- if(str[0]=='H') horizontal();
- else vertical();
- }
- else
- {
- scanf("%d %d",&bx,&by);
- for(j=0;j<3;j++) scanf("%s",a[j]);
- replace(bx,by);
- }
- }
- show();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement