-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCoding_area.cpp
191 lines (180 loc) · 4.58 KB
/
Coding_area.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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
const ll mod = 1000000007;
const ll inf = 1e18;
#define all(x) begin(x), end(x)
#define loop(i, n) for (int i = 0; i < n; i++)
#define print_array(arr) \
loop(z, sizeof(arr) / sizeof(arr[0])) cout << arr[z] << " "; \
cout << "\n"
#define print_vector(vvv) \
loop(z, vvv.size()) cout << vvv[z] << " "; \
cout << "\n"
#define print_vector_pair(vvv) \
loop(z, vvv.size()) cout << vvv[z].first << " " vvv[z].second << "\n"; \
cout << "\n"
#define fill_my(arr, q) fill(all(arr), q)
void solve()
{
int n;
cin >> n;
// cout<<n;
string s;
cin >> s;
int l = s.length();
int lenv = 0;
// cout<<s<<endl;
vector<pair<int, char>> v;
for (int i = 0; i < l; i++)
{
char c = s[i];
if (c == 'A')
{
v.emplace_back(i, 'A');
lenv++;
}
else if (c == 'B')
{
v.emplace_back(i, 'B');
lenv++;
}
// else if (c=='-')
// {
// v.emplace_back(i,'A');
// }
}
if (v[0].second == 'A' && v[0].first != 0)
{
for (int j = 0; j <= (v[0].first); j++)
{
s[j] = 'A';
}
}
if (v[0].second == 'B')
{
if (lenv > 1)
if (v[1].second == 'B')
{
for (int j = v[0].first; j <= (v[1].first); j++)
{
s[j] = 'B';
}
}
else if (v[1].second == 'A')
{
int low = v[0].first;
int high = v[1].first;
int diff = high - low - 1;
if (diff > 1)
if (diff % 2 == 0)
{
for (int j = 1; j <= (diff / 2); j++)
{
s[low + j] = 'B';
s[high - j] = 'A';
}
}
else
{
for (int j = 1; j <= (diff - 1) / 2; j++)
{
s[low + j] = 'B';
s[high - j] = 'A';
}
}
}
}
if(lenv>1)
for (int i = 1; i < lenv; i++)
{
// cout<<v[i].first<<" "<<v[i].second<<endl;
if (v[i].second == 'A')
{
if (v[i - 1].second == 'A')
{
for (int j = (v[i - 1].first); j < (v[i].first); j++)
{
s[j] = 'A';
}
}
}
else if (v[i].second == 'B')
{ if(i+1<=lenv-1)
if (v[i + 1].second == 'B')
{
for (int j = (v[i].first); j < (v[i + 1].first); j++)
{
s[j] = 'B';
}
}
else if (v[i + 1].second == 'A')
{
int low = v[i].first;
int high = v[i + 1].first;
int diff = high - low - 1;
if (diff > 1)
if (diff % 2 == 0)
{
for (int j = 1; j <= (diff / 2); j++)
{
s[low + j] = 'B';
s[high - j] = 'A';
}
}
else
{
for (int j = 1; j <= (diff - 1) / 2; j++)
{
s[low + j] = 'B';
s[high - j] = 'A';
}
}
}
}
}
int AA = 0, BB = 0;
for (int i = 0; i < l; i++)
{
char c = s[i];
if (c == 'A')
{
AA++;
}
else if (c == 'B')
{
BB++;
}
}
if (AA > BB)
{
cout << "A";
}
else if (BB > AA)
{
cout << "B";
}
else if (AA == BB)
{
cout << "Coalition government";
}
// cout << s << endl;
//cout <<a<<"\n";
}
int main()
{
clock_t time_req;
time_req = clock();
cin.sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--)
{
solve();
// }
// time_req = clock() - time_req;
// cout << "\nProcessor time " << (float)time_req / CLOCKS_PER_SEC<< " sec" << endl;
return 0;
}