UVA 257 Solution- Palinwords

/*
UVA id: shoaib05
Accepted Time; 1.236 
*/

#include<iostream>
#include<string>
#include<algorithm>
#include<string.h>
#include<cstdio>

using namespace std;

int main()
{
freopen("in.txt","r",stdin);
int len,z,i,j,ln,x;
string temp,temp2,temp3,s;
char ch[300];
bool flag;
size_t found;
while(cin>>s)
{
len=s.size();
ln=3;
flag=false;
temp3="#";
x=0;
while(ln<len)
{
z=len-ln;
for(i=x;i<=z;i++)
{
temp=s.substr(i,ln);
strcpy(ch,temp.c_str());
reverse(ch,ch+ln);
temp2=ch;
if(temp==temp2)
{
if(temp3[0]=='#')
{
temp3=temp;
x=i+1;
continue;
}
else if(temp==temp3)
continue;
else if(temp.size()>temp3.size())
{
found=temp.find(temp3);
if(found>temp.size())
{
flag=true;
cout<<s<<endl;
break;
}
temp3="#";
x=i+1;
continue;
}
else if(temp.size()==temp3.size() && temp!=temp3)
{
flag=true;
cout<<s<<endl;
break;
}
}
}
if(flag)
break;
ln++;
}
}
return 0;
}

Comments

Popular posts from this blog

uva 679 - Dropping Balls Solution

uva 481 - What Goes Up Solution

uva-10077 Solution --- The Stern-Brocot Number System