#include <bits/stdc++.h>
using namespace std;
bool czytop(string s,string s2)
{
int i,j;
i=0; j=s.size()-1;
while (i<=j)
{
if(s[i]!=s2[j]) return false;
i++;
j--;
}
return true;
}
bool czytop2(string s)
{
int i,j;
i=0; j=s.size()-1;
while (i<=j)
{
if(s[i]!=s[j]) return false;
i++;
j--;
}
return true;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
string s;
cin>>s;
int i,j,ile=0,czydalej=0;
if(s.size()==2) cout<<"-1";
if (czytop2(s))
{
cout<<0;
czydalej=-1;
}
if (czydalej!=-1)
{
string lewa,prawa;
i=0; j=s.size()-2;
lewa=s.substr(i,2);
prawa=s.substr(j,2);
if ((s.size()-1)%2!=0)
{
while(i<=s.size()-2)
{
i=i+2;
j=j-2;
ile++;
lewa=s.substr(i,2);
//prawa=s.substr(j,2);
}
}
else
{
while(!czytop2(s))
{
if (i>(s.size()-1)/2+1)
{
i=1;
j=s.size()-3;
}
if (!czytop(lewa,prawa))
swap(s[i],s[i+1]);
i=i+2;
j=j-2;
ile++;
lewa=s.substr(i,2);
//prawa=s.substr(j,1);
}
}
cout<<s;
}
}
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 | #include <bits/stdc++.h> using namespace std; bool czytop(string s,string s2) { int i,j; i=0; j=s.size()-1; while (i<=j) { if(s[i]!=s2[j]) return false; i++; j--; } return true; } bool czytop2(string s) { int i,j; i=0; j=s.size()-1; while (i<=j) { if(s[i]!=s[j]) return false; i++; j--; } return true; } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); string s; cin>>s; int i,j,ile=0,czydalej=0; if(s.size()==2) cout<<"-1"; if (czytop2(s)) { cout<<0; czydalej=-1; } if (czydalej!=-1) { string lewa,prawa; i=0; j=s.size()-2; lewa=s.substr(i,2); prawa=s.substr(j,2); if ((s.size()-1)%2!=0) { while(i<=s.size()-2) { i=i+2; j=j-2; ile++; lewa=s.substr(i,2); //prawa=s.substr(j,2); } } else { while(!czytop2(s)) { if (i>(s.size()-1)/2+1) { i=1; j=s.size()-3; } if (!czytop(lewa,prawa)) swap(s[i],s[i+1]); i=i+2; j=j-2; ile++; lewa=s.substr(i,2); //prawa=s.substr(j,1); } } cout<<s; } } |
English