-
Notifications
You must be signed in to change notification settings - Fork 0
/
winner.cpp
48 lines (38 loc) · 1.05 KB
/
winner.cpp
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
#include <bits/stdc++.h>
using namespace std;
string gameWinner(string colors)
{
int len = colors.length();
string turn = "w";
while (true)
{
bool b_found = false;
bool w_found = false;
for (int i = 0; i <= colors.length()-2; i++)
{
if (colors.substr(i, 3) == "bbb" && turn == "b")
{
colors = colors.substr(0, i + 1) + colors.substr(i + 2, len - i - 2);
b_found = true;
break;
}
if (colors.substr(i, 3) == "www" && turn == "w")
{
colors = colors.substr(0, i + 1) + colors.substr(i + 2, len - i - 2);
w_found = true;
break;
}
}
if (turn == "w" && !w_found)
return "bob";
if (turn == "b" && !b_found)
return "wendy";
if (turn == "w") turn = "b";
else turn = "w";
}
}
int main()
{
cout << gameWinner("wwwbbbbwww");
return 0;
}