ACM (UVa) : 10409


//http://uva.onlinejudge.org/external/104/10409.html

#include <iostream>
using namespace std;

int main ()
{
    int n;

    while ( cin >> n && n ) {

        int top = 1;
        int down = 6;
        int east = 4;
        int west = 3;
        int north = 2;
        int south = 5;
        int temp = 0;

        while ( n-- ) {
            string str;
            cin >> str;

            int x;
            if ( str == "north" )
                x = 0;
            else if ( str == "south" )
                x = 1;
            else if ( str == "west" )
                x = 2;
            else
                x = 3;

            switch (x) {
                case 0 :
                temp = north;
                north = top;
                top = south;
                south = down;
                down = temp;
                break;

                case 1 :
                temp = top;
                top = north;
                north = down;
                down = south;
                south = temp;
                break;

                case 2 :
                temp = top;
                top = east;
                east = down;
                down = west;
                west = temp;
                break;

                case 3 :
                temp = top;
                top = west;
                west = down;
                down = east;
                east = temp;
                break;
            }
        }

        printf ("%d\n", top);
    }

    return 0;
}

One thought on “ACM (UVa) : 10409

  1. Don’t you think the program is big. This program is too good i am not offending but i think there might be shorter code but your’s is more understandable.

    #include
    #include
    using namespace std;
    //UVA 10409
    //Vatsal Sharma 9th class student
    int main() {
    int ta;
    while(1){
    cin>>ta;
    if(ta==0) break;
    int t,n,w,top,b,s,e;
    string av;
    t=1;
    n=2;
    w=3;
    b=7-t;
    s=7-n;
    e=7-w;
    while(ta–){
    cin>>av;

    if(av[0]==’n’) { top=7-n; s=7-t; n=t; t=top;}
    if(av[0]==’s’) { top=7-s; s=t; n=7-s; t=top;}
    if(av[0]==’e’) { top=7-e; w=7-t; e=t; t=top;}
    if(av[0]==’w’) { top=7-w; w=t; e=7-w; t=top;}

    }
    cout<<top<<endl;
    }
    return 0;
    }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s