ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1297. Palindrome

Why I have time limit exceed test 15
Posted by Grigorenko Vlad 19 Jul 2012 12:51
#include<iostream>
#include<string>

using namespace std;

int isPalindrom(string);

int main(void){
    string s,s1,s2;
    int i,j,k;
    cin>>s;
    k=0;
    for(i=0;i<s.size();i++)
        for(j=1;j<=s.size();j++)
            if(isPalindrom(s.substr(i,j))){
                s1=s.substr(i,j);
                if(s1.size()>k){
                    k=s1.size();
                    s2=s1;
                }
            }
    cout<<s2;
return 0;
}

int isPalindrom(string s){
     int i,flag;
     for(i=0;i<s.size()/2;i++)
         if(s[i]!=s[s.size()-i-1]){
             flag=0;
             break;
         }
         else
             flag=1;
    if(flag)
        return 1;
    else
        return 0;
}