Advertisement
DMG

Rotacija

DMG
Mar 7th, 2013
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.89 KB | None | 0 0
  1. /* http://hsin.hr/skolska2008/pasccpp1_zadaci.pdf */
  2. #include <iostream>
  3. using namespace std;
  4. main()
  5. {
  6.       int n, m, a[3][3];
  7.      
  8.       int s = 1;
  9.       for (int i=0; i<3; i++)
  10.       for (int j=0; j<3; j++)
  11.       {a[i][j] = s; s++;}
  12.      
  13.       cin >> n;
  14.      
  15.       for (int i=0; i<n; i++)
  16.       {
  17.           cin >> m;
  18.           switch(m)
  19.           {
  20.                    case 1:
  21.                         {
  22.                           s = a[0][0];
  23.                           a[0][0] = a[1][0];
  24.                           a[1][0] = a[1][1];
  25.                           a[1][1] = a[0][1];
  26.                           a[0][1] = s;  
  27.                         } break;
  28.                        
  29.                    case 2:
  30.                         {
  31.                           s = a[0][1];
  32.                           a[0][1] = a[1][1];
  33.                           a[1][1] = a[1][2];
  34.                           a[1][2] = a[0][2];
  35.                           a[0][2] = s;  
  36.                         } break;  
  37.                        
  38.                    case 3:
  39.                         {
  40.                           s = a[1][0];
  41.                           a[1][0] = a[2][0];
  42.                           a[2][0] = a[2][1];
  43.                           a[2][1] = a[1][1];
  44.                           a[1][1] = s;  
  45.                         } break;      
  46.                        
  47.                    case 4:
  48.                         {
  49.                           s = a[1][1];
  50.                           a[1][1] = a[2][1];
  51.                           a[2][1] = a[2][2];
  52.                           a[2][2] = a[1][2];
  53.                           a[1][2] = s;  
  54.                         } break;                            
  55.           }
  56.       }
  57.      
  58.       for (int i=0; i<3; i++)
  59.       {
  60.           for (int j=0; j<3; j++)
  61.           cout << a[i][j] << " ";
  62.           cout << endl;
  63.       }
  64.      
  65.       system ("PAUSE");
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement