-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1216 A.cpp
102 lines (89 loc) · 2.8 KB
/
1216 A.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
/**
* Git >> Mohsin_Riad
░░░▄█████████████████▄
░░▐████▀▒██████████████▄
░▒██▀▒▒▒▒▒█████████▀█████
░▐██▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒████▌
░▐█▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒████▌
░░█▒▄▀▀▀▀▀▄▒▒▄▀▀▀▀▀▄▒▐███▌
░░░▐░░░▄▄░░▌▐░░░▄▄░░▌▐███▌
░▄▀▌░░░▀▀░░▌▐░░░▀▀░░▌▒▀▒█▌
░▌▒▀▄░░░░▄▀▒▒▀▄░░░▄▀▒▒▄▀▒▌
░▀▄▐▒▀▀▀▀▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒█
░░░▀▌▒▄██▄▄▄▄████▄▒▒▒▒█▀
░░░░▄██████████████▒▒▐▌
░░░▀███▀▀████▀█████▀▒▌
░░░░░▌▒▒▒▄▒▒▒▄▒▒▒▒▒▒▐
░░░░░▌▒▒▒▒▀▀▀▒▒▒▒▒▒▒▐
**/
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mx 1000
#define endl "\n"
#define pb push_back
#define pob pop_back
typedef long long ll;
typedef double dd;
const int N = 1e6;
int main()
{
IOS
ll n;
cin>>n;
char str[n+5];
cin>>str;
ll temp=2 , cnt=0;
while(n>=temp)
{
ll a=0, b=0;
for(int i=temp-2; i<temp ;i++)
{
if(str[i] == 97)
a++;
if(str[i] == 98)
b++;
//cout<<"check: loop1 "<<i<<endl;
}
if(a == b){temp += 2; continue;}
int k=temp-2;
//cout<< "a:"<<a<<"b: "<<b<<endl;
if(a > b)
{
//cout<<"check: a>b"<<endl;
while(k<=temp)
{
//cout<<"check: while 1 "<<k<<endl;
if(str[k] == 97)
{
str[k] = 98;
b++;
a--;
cnt++;
}
if(b == a) break;
else k++;
}
}
else
{
//cout<<"check: b>a"<<endl;
while(k<=temp)
{
//cout<<"check: while 2 "<<k<<endl;
if(str[k] == 98)
{
str[k] = 97;
a++;
b--;
cnt++;
}
if(a == b) break;
else k++;
}
}
temp += 2;
}
cout<<cnt<<endl<<str<<endl;
return (0);
}