#include<cstdio>
#include<string.h>
int main()
{
int N;
char side[10];
int north,south,east,west,top,bottom,tempBottom,tempTop;
while ((scanf("%d",&N)==1)&&N>0)
{
top = 1;
bottom = 6;
east = 4;
west = 3;
north = 2;
south = 5;
while (N--)
{
scanf("%s",&side);
if (strcmp(side, "north") == 0)
{
tempBottom = bottom;
tempTop = top;
top = south;
bottom = north;
south = tempBottom;
north = tempTop;
}
else if (strcmp(side, "south") == 0)
{
tempBottom = bottom;
tempTop = top;
top = north;
bottom = south;
south = tempTop;
north = tempBottom;
}
else if (strcmp(side, "east") == 0)
{
tempBottom = bottom;
tempTop = top;
top = west;
bottom = east;
west = tempBottom;
east = tempTop;
}
else if (strcmp(side, "west") == 0)
{
tempBottom = bottom;
tempTop = top;
top = east;
bottom = west;
east = tempBottom;
west = tempTop;
}
}
printf("%d\n",top);
}
}
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.
ReplyDelete#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;
}