samedi 3 septembre 2016

This code is running perfectly fine in Atom whereas on codechef is showing Wrong Answer.

This is the code to convert a string into a palindrome in lexicographic method by filling a '.'. e.g cb.bc into cbabc and printing -1 if not possible.

This is running well on my macbook and ideone but showing "Wrong Answer" on Codechef. I am unable to understand why and for what test case this is pringting wrong answer. please help. thanks

#include<iostream>
#include<algorithm>

using namespace std ;

int main()
{
  int i,k,t,m ;
  string s1,s2 ;
cin>>t ;
for(m=1;m<=t;m++)
{
  cin>>s1 ;
int z= s1.length();
for(i=0;i<z;i++)
{
  if(s1[i]=='.')
  {
  break ;
  }
}
for(k=97; k<=122; k++ )
{
  s1[i]=char(k);
  s2=s1;
  reverse(s2.begin(),s2.end()) ;
 if(s1==s2)
{
  cout<<s1<<endl ;
  break ;
}
}
if(s1!=s2)
{
  cout<< " -1 " <<endl;
}
}
return 0 ;
}




Aucun commentaire:

Enregistrer un commentaire