A1. Gardener and the Capybaras (easy version)
A2. Gardener and the Capybaras (hard version)
Consider five cases to solve the task:
If the string starts with
a
a
aa
aa, then we can split it into
a
=
s
[
0
]
a = s[0]
a=s[0],
b
=
s
[
1
]
b = s[1]
b=s[1],
c
=
s
[
2...
n
−
1
]
c = s[2 ... n - 1]
c=s[2...n−1].
If the string starts with
b
b
bb
bb, then we can split it into
a
=
s
[
0
]
a = s[0]
a=s[0],
b
=
s
[
1
]
b = s[1]
b=s[1],
c
=
s
[
2...
n
−
1
]
c = s[2 ... n - 1]
c=s[2...n−1].
If the string starts with
b
a
ba
ba, then we can split it into
a
=
s
[
0
]
a = s[0]
a=s[0],
b
=
s
[
1
]
b = s[1]
b=s[1],
c
=
s
[
2...
n
−
1
]
c = s[2 ... n - 1]
c=s[2...n−1].
If the string starts with
a
b
ab
ab, and then there is another letter a at position
i
>
1
i > 1
i>1, then we can split it into
a
=
s
[
0
]
a = s[0]
a=s[0],
b
=
s
[
1...
i
−
1
]
b = s[1 ... i - 1]
b=s[1...i−1],
c
=
s
[
i
.
.
.
n
−
1
]
c = s[i ... n - 1]
c=s[i...n−1].
If the string starts with
a
b
ab
ab, and all other letters are b, then we can split it into
a
=
s
[
0...
n
−
3
]
a = s[0 ... n - 3]
a=s[0...n−3],
b
=
s
[
n
−
2
]
b = s[n - 2]
b=s[n−2],
c
=
s
[
n
−
1
]
c = s[n - 1]
c=s[n−1].
#include<bits/stdc++.h>
using namespace std;
int main()
{
int T;cin>>T;
while(T--)
{
string s;cin>>s;
int pos=0;
for(int i=1;i<s.size()-1;i++)
if(s[i]=='a')
{
pos=i;
break;
}
if(pos) cout<<s.substr(0,pos)<<" a "<<s.substr(pos+1)<<endl;
else cout<<s[0]<<" "<<s.substr(1,s.size()-2)<<" "<<s.back()<<endl;
}
return 0;
}