-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA_AB_Balance.cpp
More file actions
45 lines (41 loc) · 978 Bytes
/
A_AB_Balance.cpp
File metadata and controls
45 lines (41 loc) · 978 Bytes
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
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
while (t--)
{
string s;
cin >> s;
int countab = 0, countba = 0;
size_t abPosition = s.find("ab");
while (abPosition != string::npos)
{
countab++;
abPosition = s.find("ab", abPosition + 1);
}
size_t baPosition = s.find("ba");
while (baPosition != string::npos)
{
countba++;
baPosition = s.find("ba", baPosition + 1);
}
// int abi = s.find("ab");
// int bai = s.find("ba");
if (s[0] == 'a')
{
if (countab > countba)
{
s[0] = 'b';
}
}
else
{
if (countba > countab)
{
s[0] = 'a';
}
}cout << s << endl;
}return 0;
}