-
Notifications
You must be signed in to change notification settings - Fork 0
/
763-c.cpp
61 lines (57 loc) · 1.01 KB
/
763-c.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
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <sstream>
#include <fstream>
#include <functional>
#include <array>
#include <climits>
//#include "debug.h"
using namespace std;
#define A first
#define B second
typedef long long ll;
constexpr int MOD = 1e9 + 7;
void solve(){
string S;
cin >> S;
int ab = 0, ba = 0;
if(S.size() == 1) {
cout << S << '\n';
return;
}
for(int i = 1; i < S.size(); i++) {
if(S[i] == 'b' && S[i - 1] == 'a') ab++;
else if(S[i] == 'a' && S[i - 1] == 'b') ba++;
}
if(ab == ba) {
cout << S << '\n';
return;
} else if(ab > ba) {
S[0] = 'b';
cout << S << '\n';
} else if(ab < ba) {
S[0] = 'a';
cout << S << '\n';
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int T;
T = 1;
cin >> T;
while(T--) {
solve();
}
}