Problem solving criteria:Just check palindrome or not
Palindrome:a word, phrase, or sequence that reads the same backwards as forwards.
checking palindrome:revserse a string then checking it is equal to the previous string.
rev=str;
reverse(rev.begin(),rev.end());
if(rev==str) print(palindrome)
///Bismillahir Rahmanir Rahim
///Author: Tanvir Ahmmad
///CSE,Islamic University,Bangladesh
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<vector>
#include<iterator>
#include <functional> ///sort(arr,arr+n,greater<int>()) for decrement of array
/*every external angle sum=360 degree
angle find using polygon hand(n) ((n-2)*180)/n*/
///Floor[Log(b) N] + 1 = the number of digits when any number is represented in base b
using namespace std;
typedef long long ll;
int main()
{
int tst;
cin>>tst;
while(tst--)
{
string str,rev;
cin>>str;
rev=str;
reverse(rev.begin(),rev.end());
if(rev==str)
{
for(int i=1; i<str.size(); i++)
if(str[0]!=str[i])
{
swap(str[0],str[i]);
break;
}
rev=str;
reverse(rev.begin(),rev.end());
if(rev==str) cout<<"-1"<<endl;
else cout<<str<<endl;
}
else cout<<str<<endl;
}
return 0;
}
///Alhamdulillah
Problem Link:https://codeforces.com/contest/1093/problem/B
Comments
Post a Comment