-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpalindrome_substring.cpp
More file actions
85 lines (84 loc) · 1.36 KB
/
palindrome_substring.cpp
File metadata and controls
85 lines (84 loc) · 1.36 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
77
78
79
80
81
82
83
84
85
#include <bits/stdc++.h>
using namespace std;
void Solve()
{
int N;
cin >> N;
string a;
cin >> a;
if (N == 1)
{
cout << "BOB" << endl;
return;
}
if (N == 2)
{
if (a[0] == a[1])
{
cout << "ALICE" << endl;
}
else
{
cout << "BOB" << endl;
}
return;
}
bool Found = true;
int ATurns = 0;
int BTurns = 0;
int Zeroes = 0;
int Ones = 0;
for (int i = 0; i < N; i++)
{
if (a[i] == '0')
{
Zeroes++;
}
else
{
Ones++;
}
}
for (int i = 0; i < N - 2; i++)
{
if (i % 2 == 0)
{
ATurns++;
}
else
{
BTurns++;
}
}
if (N % 2 == 0)
{
if (ATurns >= Zeroes || ATurns >= Ones)
{
cout << "ALICE" << endl;
}
else
{
cout << "BOB" << endl;
}
}
else
{
if (BTurns >= Zeroes || BTurns >= Ones)
{
cout << "Bob" << endl;
}
else
{
cout << "ALICE" << endl;
}
}
}
int main()
{
int T;
cin >> T;
while (T--)
{
Solve();
}
}