-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuno.cpp
More file actions
64 lines (58 loc) · 1.44 KB
/
Copy pathuno.cpp
File metadata and controls
64 lines (58 loc) · 1.44 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
#include <iostream>
using namespace std;
int runMove(int position, int direction, int maxPlayers) {
// returns back the new postion
if (direction == -1) {
// we are going in reverse
if (position == 0)
position = maxPlayers;
else
position--;
} else {
if (position == maxPlayers)
position = 0;
else
position++;
}
return position;
}
void runTestCase() {
int n, k;
cin >> n >> k;
char *cards = new char[k];
for (int i = 0; i < k; i++) {
cin >> cards[i];
}
int *players = new int[n];
for (int i = 0; i < n; i++) {
players[i] = i;
}
int position = 0;
int direction = 1;
for (int i = 0; i < k; i++) {
char move = cards[i];
// cout << "move: " << move << " pos: " << position;
switch (move)
{
case 'U':
position = runMove(position, direction, n-1);
break;
case 'S':
position = runMove(position, direction, n-1);
position = runMove(position, direction, n-1);
break;
case 'R':
direction *= -1;
position = runMove(position, direction, n-1);
break;
}
// cout << " new pos: " << position << endl;
}
cout << position+1 << endl;
}
int main() {
int T;
cin >> T;
for (int i = 0; i < T; i++) runTestCase();
return 0;
}