Advertisement
Nayeemzaman

mentalRotation

Aug 17th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.66 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. char arr[1005][1005];
  5. string s;
  6. int n;
  7.  
  8. void rotateleft()
  9. {
  10.     char temp[1005][1005];
  11.     for(int i=0; i<n; i++)
  12.     {
  13.         for(int j=0; j<n; j++)
  14.         {
  15.             if(arr[i][j]== 'v')
  16.                 temp[n-j-1][i]='>';
  17.             else if(arr[i][j]== '>')
  18.                 temp[n-j-1][i]='^';
  19.             else if(arr[i][j]== '<')
  20.                 temp[n-j-1][i]='v';
  21.             else if(arr[i][j]== '^')
  22.                 temp[n-j-1][i]='<';
  23.             else
  24.                 temp[n-j-1][i]=arr[i][j];
  25.         }
  26.  
  27.     }
  28.     for(int i=0; i<n; i++)
  29.         for(int j=0; j<n; j++)
  30.              arr[i][j]=temp[i][j];
  31.  
  32. }
  33. void rotateright()
  34. {
  35.     char temp[1005][1005];
  36.     for(int i=0; i<n; i++)
  37.     {
  38.         for(int j=0; j<n; j++)
  39.         {
  40.             if(arr[i][j]== 'v')
  41.                 temp[j][n-i-1]='<';
  42.             else if(arr[i][j]== '>')
  43.                 temp[j][n-i-1]='v';
  44.             else if(arr[i][j]== '<')
  45.                 temp[j][n-i-1]='^';
  46.             else if(arr[i][j]== '^')
  47.                 temp[j][n-i-1]='>';
  48.             else
  49.                 temp[j][n-i-1]=arr[i][j];
  50.         }
  51.  
  52.     }
  53.     for(int i=0; i<n; i++)
  54.         for(int j=0; j<n; j++)
  55.              arr[i][j]=temp[i][j];
  56.  
  57. }
  58. int main()
  59. {
  60.  
  61.  
  62.     cin>>n>>s;
  63.  
  64.     for(int i=0; i<n; i++)
  65.         for(int j=0; j<n; j++)
  66.              cin>>arr[i][j];
  67.  
  68.     for(int i=0; i<s.size(); i++)
  69.     {
  70.         if(s[i]=='R')
  71.            rotateright();
  72.         else rotateleft();
  73.     }
  74.     for(int i=0; i<n; i++)
  75.     {
  76.         for(int j=0; j<n; j++)
  77.              cout<<arr[i][j];
  78.         cout<<endl;
  79.     }
  80.  
  81.     return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement