Created
November 2, 2014 12:26
-
-
Save amoshyc/695b3caa9989e973b606 to your computer and use it in GitHub Desktop.
uva10409.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
int main() { | |
int N; | |
while (scanf("%d", &N)) { | |
if (N == 0) break; | |
int top = 1; | |
int front = 2; | |
int left = 3; | |
while (N--) { | |
char inp[10]; | |
scanf("%s", inp); | |
if (inp[0] == 'n') { | |
int new_top = 7 - front; | |
int new_front = top; | |
int new_left = left; | |
top = new_top; | |
front = new_front; | |
left = new_left; | |
} | |
else if (inp[0] == 'e') { | |
int new_top = left; | |
int new_front = front; | |
int new_left = 7 - top; | |
top = new_top; | |
front = new_front; | |
left = new_left; | |
} | |
else if (inp[0] == 's') { | |
int new_top = front; | |
int new_front = 7 - top; | |
int new_left = left; | |
top = new_top; | |
front = new_front; | |
left = new_left; | |
} | |
else { /* inp[0] == 'w' */ | |
int new_top = 7 - left; | |
int new_front = front; | |
int new_left = top; | |
top = new_top; | |
front = new_front; | |
left = new_left; | |
} | |
} | |
printf("%d\n", top); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment