Re: [algogeeks] convert a word into a palindrome with minimum addition of letters to it

2011-09-05 Thread bharatkumar bagana
@hemank:
sukran's prog works ..
int main()
{
char str[]=Nitan;
int n=strlen(str);
for(int i=0;in/2;i++)
{
str[n-1-i] = str[i];
}
printf(%s,str);
}
ouput :NitiN

On Mon, Sep 5, 2011 at 4:39 AM, SANDEEP CHUGH sandeep.aa...@gmail.comwrote:


 #includeconio.h
 #includestdio.h
 #includestring.h
 #includeiostream.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(i2i1)
  {
  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 hemankla...@gmail.comwrote:

 @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 sukrandha...@gmail.comwrote:



 On Sun, Sep 4, 2011 at 11:11 PM, sukran dhawan 
 sukrandha...@gmail.comwrote:

 for(i0;in/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 nimish7andr...@gmail.comwrote:

 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 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.



  --
 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.


  --
 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.


  --
 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.




-- 

**Please do not print this e-mail until urgent requirement. Go Green!!
Save Papers = Save Trees
*BharatKumar Bagana*
**http://www.google.com/profiles/bagana.bharatkumarhttp://www.google.com/profiles/bagana.bharatkumar
*
Mobile +91 8056127652*
bagana.bharatku...@gmail.com

-- 
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.



Re: [algogeeks] convert a word into a palindrome with minimum addition of letters to it

2011-09-05 Thread SANDEEP CHUGH
@bharat :  you are changing the original string..  i think we don't have to
do that.. we just have to add characters to the existing string so as to
make it palindrome

u see my program .. do tell me if there is some prob..

On Mon, Sep 5, 2011 at 5:34 PM, bharatkumar bagana 
bagana.bharatku...@gmail.com wrote:

 @hemank:
 sukran's prog works ..
 int main()
 {
 char str[]=Nitan;
 int n=strlen(str);
 for(int i=0;in/2;i++)
 {
 str[n-1-i] = str[i];
 }
 printf(%s,str);
 }
 ouput :NitiN

 On Mon, Sep 5, 2011 at 4:39 AM, SANDEEP CHUGH sandeep.aa...@gmail.comwrote:


 #includeconio.h
 #includestdio.h
 #includestring.h
 #includeiostream.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(i2i1)
  {
  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 hemankla...@gmail.comwrote:

 @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 
 sukrandha...@gmail.comwrote:



 On Sun, Sep 4, 2011 at 11:11 PM, sukran dhawan 
 sukrandha...@gmail.comwrote:

 for(i0;in/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 nimish7andr...@gmail.comwrote:

 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 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.



  --
 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.


  --
 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.


  --
 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.




 --

 **Please do not print this e-mail until urgent requirement. Go Green!!
 Save Papers = Save Trees
 *BharatKumar Bagana*
 **http://www.google.com/profiles/bagana.bharatkumarhttp://www.google.com/profiles/bagana.bharatkumar
 *
 Mobile +91 8056127652*
 bagana.bharatku...@gmail.com


  --
 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.


-- 
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.



Re: [algogeeks] convert a word into a palindrome with minimum addition of letters to it

2011-09-04 Thread sukran dhawan
for(i0;in/2;i++)
{
a[n-1-i] = a[i];
}

will this work ?

On Sun, Sep 4, 2011 at 7:54 PM, learner nimish7andr...@gmail.com 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 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.



-- 
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.



Re: [algogeeks] convert a word into a palindrome with minimum addition of letters to it

2011-09-04 Thread sukran dhawan
On Sun, Sep 4, 2011 at 11:11 PM, sukran dhawan sukrandha...@gmail.comwrote:

 for(i0;in/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 nimish7andr...@gmail.com 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 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.




-- 
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.



Re: [algogeeks] convert a word into a palindrome with minimum addition of letters to it

2011-09-04 Thread hemank lamba
@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 sukrandha...@gmail.comwrote:



 On Sun, Sep 4, 2011 at 11:11 PM, sukran dhawan sukrandha...@gmail.comwrote:

 for(i0;in/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 nimish7andr...@gmail.com 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 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.



  --
 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.


-- 
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.