-
Notifications
You must be signed in to change notification settings - Fork 0
/
A2.cpp
53 lines (52 loc) · 1.06 KB
/
A2.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
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
int main()
{
fastio;
int t,i,n;
string s;
cin>>t;
while(t--)
{
cin>>s;
n=s.size();
if(s[0]==s[n-1])
{
cout<<s[0]<<" ";
for(i=1;i<n-1;i++)
cout<<s[i];
cout<<" "<<s[n-1]<<"\n";
}
else
{
int f=-1;
for(i=1;i<n-1;i++)
{
if(s[i]=='a')
{
f=i;
break;
}
}
if(f!=-1)
{
for(i=0;i<f;i++)
cout<<s[i];
cout<<" a ";
for(i=f+1;i<n;i++)
cout<<s[i];
cout<<"\n";
}
else
{
cout<<s[0]<<" ";
for(i=1;i<n-1;i++)
cout<<s[i];
cout<<" "<<s[n-1]<<"\n";
}
}
}
return 0;
}