Thread: string manipulate

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    222

    string manipulate

    I am trying to resolve the below string manipulation.
    But code doesn't work as expected. Need help with some inputs.

    Input

    First line of input contains string M, consisting of lowercase English letters. Second line of input contains integer N, consisting of characters to be removed.

    Output

    Print 1 if string is k-drome, 0 otherwise. Here the constraint is 1 <= length of M <= 100



    Code:
    //function to resolve the string
    bool isKdrom(char * M, int N, int k)
    {
    	while (N >=1 && M[0] == M[N-1])
    	{
    		M++; N-=2;
    	}
    
    	if (N <= 1) return true;
    
    	if (k > 0)
    		return isKdrom(M+ 1, N-1, k-1) || isKdrom(M, N-1, k-1);
    
    	return false;
    }
    Last edited by leo2008; 01-08-2022 at 08:29 AM.

  2. #2
    Registered User
    Join Date
    Dec 2017
    Posts
    1,626
    Your question makes no sense to me.
    What is "k-drome"?
    What do you mean "characters to remove"?
    In what way does it not "work as expected"?
    A little inaccuracy saves tons of explanation. - H.H. Munro

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    222
    Quote Originally Posted by john.c View Post
    Your question makes no sense to me.
    What is "k-drome"?
    What do you mean "characters to remove"?
    In what way does it not "work as expected"?


    Below are the comments added inline here.

    What is "k-drome"? A string is k-drome if it can be transformed into a palindrome, by removing at the most N characters from it.

    What do you mean "characters to remove"? I am given a string and a number N, and I am trying to find out if that string is K-drome or not.

    In what way does it not "work as expected"? It has some logic issue here, so not working as expected. do you have any suggestions for this?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to manipulate binary?
    By S56A in forum C Programming
    Replies: 2
    Last Post: 10-05-2013, 06:24 PM
  2. string manipulate
    By thinice16 in forum C Programming
    Replies: 3
    Last Post: 08-01-2008, 07:30 PM
  3. Manipulate a string?
    By nvrmaried in forum C++ Programming
    Replies: 4
    Last Post: 09-22-2003, 02:23 PM
  4. How to manipulate a string
    By Basia in forum C Programming
    Replies: 4
    Last Post: 09-29-2002, 09:35 PM

Tags for this Thread