Advertisement
Guest User

Untitled

a guest
Oct 3rd, 2014
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.15 KB | None | 0 0
  1. /*
  2.     Codeforces Gym S02E04 problem D
  3.     sakib_rulez
  4.  
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <iostream>
  9.  
  10. using namespace std;
  11.  
  12. int sx,sy,dx,dy,n;
  13. bool inv;
  14. char g[1005][1005],a[5][5];
  15.  
  16. void calc()
  17. {
  18.     if(sx==1) dx=1;
  19.     else dx=-1;
  20.  
  21.     if(sy==1) dy=1;
  22.     else dy=-1;
  23. }
  24.  
  25. void rotate()
  26. {
  27.     // inv means present row orientation is inverted to the columns
  28.     // of original grid and vice versa
  29.     inv^=1;
  30.  
  31.     if(sx==1 && sy==1) sx=n;
  32.     else if(sx==n && sy==1) sy=n;
  33.     else if(sx==n && sy==n) sx=1;
  34.     else if(sx==1 && sy==n) sy=1;
  35.  
  36.     calc();
  37. }
  38.  
  39. void horizontal()
  40. {
  41.     sx=n+1-sx;
  42.     calc();
  43. }
  44.  
  45. void vertical()
  46. {
  47.     sy=n+1-sy;
  48.     calc();
  49. }
  50.  
  51. void replace(int bx,int by)
  52. {
  53.     int i,j;
  54.     for(i=0;i<3;i++)
  55.     {
  56.         for(j=0;j<3;j++)
  57.         {
  58.             if(!inv)    g[sx+dx*(i+bx-1)][sy+dy*(j+by-1)]=a[i][j];
  59.  
  60.             else g[sy+dy*(j+by-1)][sx+dx*(i+bx-1)]=a[i][j];
  61.         }
  62.     }
  63. }
  64.  
  65. void show()
  66. {
  67.     int i,j;
  68.     for(i=0;i<n;i++)
  69.     {
  70.         for(j=0;j<n;j++)
  71.         {
  72.             if(!inv) printf("%c",g[sx+dx*i][sy+dy*j]);
  73.             else
  74.                 printf("%c",g[sy+dy*j][sx+dx*i]);
  75.         }
  76.         printf("\n");
  77.     }
  78. }
  79.  
  80. int main()
  81. {
  82.     int i,j,k,q,bx,by;
  83.     char str[20];
  84.  
  85.     scanf("%d %d",&n,&q);
  86.  
  87.     for(i=1;i<=n;i++) for(j=1;j<=n;j++) g[i][j]='.';
  88.  
  89.     sx=sy=dx=dy=1;
  90.  
  91.     for(i=0;i<q;i++)
  92.     {
  93.         scanf("%s",str);
  94.  
  95.         //Rotate
  96.  
  97.         if(str[1]=='O')
  98.         {
  99.             scanf("%s",str);
  100.  
  101.             if(str[1]=='C') rotate(); //Rotate CounterClockWise
  102.             else
  103.             {
  104.                 //Rotate Clockwise = Roatete Counterclockwise 3 times
  105.                 rotate();
  106.                 rotate();
  107.                 rotate();
  108.             }
  109.  
  110.         }
  111.  
  112.         //MIRROR
  113.  
  114.         else if(str[1]=='I')
  115.         {
  116.             scanf("%s",str);
  117.  
  118.             if(str[0]=='H') horizontal();
  119.             else vertical();
  120.         }
  121.  
  122.         else
  123.         {
  124.             scanf("%d %d",&bx,&by);
  125.  
  126.             for(j=0;j<3;j++) scanf("%s",a[j]);
  127.  
  128.             replace(bx,by);
  129.         }
  130.  
  131.  
  132.     }
  133.  
  134.     show();
  135.  
  136.     return 0;
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement