|
|
back to boardWhy I have time limit exceed test 15 #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; } |
|
|