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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to