take “aabab” for example, the result is "aba, b,a"; however, the right result is "aa,bab"
On Wed, May 11, 2011 at 10:57 AM, shubham <shubh2...@gmail.com> wrote: > check this one out: > > #include<iostream> > #include<cstdio> > #include<vector> > #include<cstring> > using namespace std; > int check_palin(string str,int *start) > { > int pos=-1,ret,size=str.size()-1; > char last_char=str[size]; > while(pos<size) > { > ret=0;int i; > pos=str.find(last_char,pos+1); > for(i=0;i<=(size-pos);i++) > if(str[i+pos]!=str[size-i]) break; > if(i==size-pos+1){(*start)=pos;return (size-pos+1);} > } > } > int main() > { > string arr; > vector<string> palin,str; > cin>>arr;str.push_back(arr); > while(arr!="") > { > int s=0,e=0,max=0,start=0,end=0,len; > string tmp=""; > for(int i=0;i<arr.size();i++) > { > tmp+=arr[i]; > len=check_palin(tmp,&s); > if(len>max){max=len;start=s;} > } > tmp=arr.substr(start,max); > palin.push_back(tmp);str.pop_back(); > tmp=arr.substr(0,start);if(tmp!="") str.push_back(tmp); > tmp=arr.substr(start+max);if(tmp!="") str.push_back(tmp); > if(str.size())arr=str[str.size()-1];else arr=""; > } > for(int i=0;i<palin.size();i++) cout<<palin[i]<<" "; > return 0; > } > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- Regards Anders -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.