Uva 10409 --- Dice

  1. // Uva 10409 -- die game
  2. #include <iostream>
  3. using namespace std;
  4. int main()
  5. {
  6. int iCommand, i, j, k, iTemp;
  7. string sIn;
  8. while ( cin >> iCommand )  
  9.     {
  10.     if ( iCommand == 0 )
  11.         break; 
  12.     //             top  down north west east south
  13.     int iDice[6] = { 1 , 6,  2   , 3  , 4  , 5  };
  14.     string sDice[4] = { "north""west" , "east" , "south"};   
  15.     for ( i=0 ; i<iCommand ; i++ )
  16.         {
  17.         cin >> sIn;
  18.         for ( j=0 ; j<4 ; j++ )
  19.             {
  20.             if ( sDice[j] == sIn ) 
  21.                 {
  22.                 if ( j == 0 )    // north
  23.                     {
  24.                     iTemp = iDice[2];
  25.                     iDice[2] = iDice[0];
  26.                     iDice[0] = iDice[5];
  27.                     iDice[5] = iDice[1];
  28.                     iDice[1] = iTemp;  
  29.                     }  
  30.                 if ( j == 3 )   // south
  31.                     {
  32.                     iTemp = iDice[5];
  33.                     iDice[5] = iDice[0];
  34.                     iDice[0] = iDice[2];
  35.                     iDice[2] = iDice[1];
  36.                     iDice[1] = iTemp;      
  37.                     }
  38.                 if ( j == 1 )  // west
  39.                     {
  40.                     iTemp = iDice[3];
  41.                     iDice[3] = iDice[0];
  42.                     iDice[0] = iDice[4];
  43.                     iDice[4] = iDice[1];
  44.                     iDice[1] = iTemp;  
  45.                     }  
  46.                 if ( j == 2 )  //east
  47.                     {
  48.                     iTemp = iDice[4];
  49.                     iDice[4] = iDice[0];
  50.                     iDice[0] = iDice[3];
  51.                     iDice[3] = iDice[1];
  52.                     iDice[1] = iTemp;      
  53.                     }  
  54.                 }
  55.             }
  56.         //cout << " top " << iDice[0] << " ";  
  57.         }  
  58.     cout  << iDice[0] <<endl;  
  59.     }
  60.    
  61. }

留言

這個網誌中的熱門文章

Codeforces --- string task

Uva 674 ---- coin change

codeforces 271A --- beautiful year