Uva 10409 --- Dice
- // Uva 10409 -- die game
- #include <iostream>
- using namespace std;
- int main()
- {
- int iCommand, i, j, k, iTemp;
- string sIn;
- while ( cin >> iCommand )
- {
- if ( iCommand == 0 )
- break;
- // top down north west east south
- int iDice[6] = { 1 , 6, 2 , 3 , 4 , 5 };
- string sDice[4] = { "north", "west" , "east" , "south"};
- for ( i=0 ; i<iCommand ; i++ )
- {
- cin >> sIn;
- for ( j=0 ; j<4 ; j++ )
- {
- if ( sDice[j] == sIn )
- {
- if ( j == 0 ) // north
- {
- iTemp = iDice[2];
- iDice[2] = iDice[0];
- iDice[0] = iDice[5];
- iDice[5] = iDice[1];
- iDice[1] = iTemp;
- }
- if ( j == 3 ) // south
- {
- iTemp = iDice[5];
- iDice[5] = iDice[0];
- iDice[0] = iDice[2];
- iDice[2] = iDice[1];
- iDice[1] = iTemp;
- }
- if ( j == 1 ) // west
- {
- iTemp = iDice[3];
- iDice[3] = iDice[0];
- iDice[0] = iDice[4];
- iDice[4] = iDice[1];
- iDice[1] = iTemp;
- }
- if ( j == 2 ) //east
- {
- iTemp = iDice[4];
- iDice[4] = iDice[0];
- iDice[0] = iDice[3];
- iDice[3] = iDice[1];
- iDice[1] = iTemp;
- }
- }
- }
- //cout << " top " << iDice[0] << " ";
- }
- cout << iDice[0] <<endl;
- }
- }
留言
張貼留言