#include <stdio.h>
#include <string.h>

int is_palindrome(char* string, int start, int end)
{
        int i = start, j = end;

        while (start <= end) {
                if (string[start++] != string[end--])
                        return 0;
        }

        /* print */
        printf("[%d,%d] ", i, j);
        while ( i <= j)
                printf("%c", string[i++]);
        printf("\n");

        return 1;
}

int main(int argc, char** argv)
{
        int i, j, k;
        int len;
        char *p;

        if (argc != 2) {
                printf("usage padin (string)\n");
                return 0;
        }
        p = argv[1];
BEGIN:

        len = strlen(p);
        for (i = 0; i < len; i++) {
                for (j = i, k = len; j <= k; k--)
                        if (is_palindrome(p, j, k)) {
                                p += k - j + 1;
                                goto BEGIN;
                        }
        }

        return 0;
}

anders@ubuntu:~/c$ ./palin helloworld
[0,0] h
[0,0] e
[0,1] ll
[0,2] owo
[0,0] r
[0,0] l
[0,0] d
anders@ubuntu:~/c$ ./palin madamamadam
[0,10] madamamadam
anders@ubuntu:~/c$



On Fri, May 6, 2011 at 8:58 PM, sourabh jakhar <sourabhjak...@gmail.com> wrote:
>
>
> On Fri, May 6, 2011 at 4:23 PM, sourabh jakhar <sourabhjak...@gmail.com>
> wrote:
>>
>> You are given a large string. You need to cut the string into chunks such
>> that each substring that you get is a palindrome. Remember that each 1
>> length string is always a palindrome. You need to find the minimum number of
>> cuts that you need to make such that each substring is a palindrome.
>>
>> --
>> SOURABH JAKHAR,(CSE)(3 year)
>> ROOM NO 167 ,
>> TILAK,HOSTEL
>> 'MNNIT ALLAHABAD
>>
>> The Law of Win says, "Let's not do it your way or my way; let's do it the
>> best way."
>>
>> --
>> 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.
>
>
>
> --
> SOURABH JAKHAR,(CSE)(3 year)
> ROOM NO 167 ,
> TILAK,HOSTEL
> 'MNNIT ALLAHABAD
>
> The Law of Win says, "Let's not do it your way or my way; let's do it the
> best way."
>
> --
> 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.

Reply via email to