@hemank:
sukran's prog works ..
int main()
{
char str[]="Nitan";
int n=strlen(str);
for(int i=0;i<n/2;i++)
{
str[n-1-i] = str[i];
}
printf("%s",str);
}
ouput :NitiN
On Mon, Sep 5, 2011 at 4:39 AM, SANDEEP CHUGH <[email protected]>wrote:
>
> #include<conio.h>
> #include<stdio.h>
> #include<string.h>
> #include<iostream.h>
>
> void substr(char *dst,char *src, size_t start, size_t stop)
> {
> int count = stop - start;
>
> sprintf(dst, "%.*s", count, src + start);
>
> }
>
> int ispalin(char *k)
> {
> int i1=0;
> int i2=strlen(k)-1;
> while(i2>i1)
> {
> if(k[i2]!=k[i1])
> return 0;
>
> i1++;
> i2--;
> }
> return 1;
> }
>
> void makepalin(char *t)
> {
> char s[50];
> char *p=t;
>
> int i=0;
> char k[50];
> while (!ispalin(p))
> {
> s[i]=p[0];
>
> substr(p,p,1,(strlen(t)));
>
> i++;
> }
>
> strcpy(k,s);
> strcat(k,p);
> strcat(k,strrev(s));
>
> printf(" palin is %s ",k);
>
> }
>
> int main( )
> {
> char s[50];
> gets(s);
> makepalin(s);
>
>
> getch();
> }
>
>
> On Mon, Sep 5, 2011 at 10:46 AM, hemank lamba <[email protected]>wrote:
>
>> @Sukran: This wont work for the test case like this
>>
>> for example the word is "Nitan":
>> then the word ur algorithm will create is "Nitanatin" hence the number of
>> additions =4
>>
>> but ideal case i would be
>> "nitatin" : where number of additions is only 2.
>>
>> On Sun, Sep 4, 2011 at 11:11 PM, sukran dhawan <[email protected]>wrote:
>>
>>>
>>>
>>> On Sun, Sep 4, 2011 at 11:11 PM, sukran dhawan
>>> <[email protected]>wrote:
>>>
>>>> for(i0;i<n/2;i++)
>>>> {
>>>> a[n-1-i] = a[i];
>>>> }
>>>>
>>>> will this work ?
>>>> where n is the length os string
>>>>
>>>>
>>>> On Sun, Sep 4, 2011 at 7:54 PM, learner <[email protected]>wrote:
>>>>
>>>>> Given a word, convert it into a palindrome with minimum addition of
>>>>> letters to it. letters can be added anywhere in the word. for eg if
>>>>> yahoo is given result shud be yahohay.
>>>>>
>>>>>
>>>>> Thanks
>>>>>
>>>>> --
>>>>> 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.
>>>>>
>>>>>
>>>>
>>> --
>>> 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.
>>>
>>
>> --
>> 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.
>>
>
> --
> 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.
>
--
**Please do not print this e-mail until urgent requirement. Go Green!!
Save Papers <=> Save Trees
*BharatKumar Bagana*
**http://www.google.com/profiles/bagana.bharatkumar<http://www.google.com/profiles/bagana.bharatkumar>
*
Mobile +91 8056127652*
<[email protected]>
--
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.