-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy path10409.cpp
More file actions
executable file
·76 lines (71 loc) · 2.2 KB
/
10409.cpp
File metadata and controls
executable file
·76 lines (71 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* Problem: Die Game UVa 10409
Programmer: Md. Mahmud Ahsan
Compiled: Visual C++ 6.0
Date: 10-10-04
*/
#include <iostream>
#include <string>
using namespace std;
// prototypes
void callEast(int &top, int &bottom, int &east, int &west, int &north, int &south);
void callWest(int &top, int &bottom, int &east, int &west, int &north, int &south);
void callNorth(int &top, int &bottom, int &east, int &west, int &north, int &south);
void callSouth(int &top, int &bottom, int &east, int &west, int &north, int &south);
//==========================================================================
int main(){
int top, bottom, east, west, north, south;
int command;
char str[100];
int i;
while (cin >> command){
if (command == 0) break;
// first initialized
top = 1; bottom = 6; east = 4; west = 3; north = 2; south = 5;
for (i = 0; i < command; i++){
cin >> str;
if (strcmp(str, "north") == 0)
callNorth(top, bottom, east, west, north, south);
else if (strcmp(str, "south") == 0)
callSouth(top, bottom, east, west, north, south);
else if (strcmp(str, "east") == 0)
callEast(top, bottom, east, west, north, south);
else if (strcmp(str, "west") == 0)
callWest(top, bottom, east, west, north, south);
}
cout << top << endl;
}
return 0;
}
//============================================================================
void callNorth(int &top, int &bottom, int &east, int &west, int &north, int &south){
int tempBottom = bottom;
int tempTop = top;
top = south;
bottom = north;
south = tempBottom;
north = tempTop;
}
void callSouth(int &top, int &bottom, int &east, int &west, int &north, int &south){
int tempBottom = bottom;
int tempTop = top;
top = north;
bottom = south;
south = tempTop;
north = tempBottom;
}
void callEast(int &top, int &bottom, int &east, int &west, int &north, int &south){
int tempBottom = bottom;
int tempTop = top;
top = west;
bottom = east;
west = tempBottom;
east = tempTop;
}
void callWest(int &top, int &bottom, int &east, int &west, int &north, int &south){
int tempBottom = bottom;
int tempTop = top;
top = east;
bottom = west;
east = tempBottom;
west = tempTop;
}