Thread: string manipulate

Threaded View

Previous Post Previous Post   Next Post Next Post
  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.

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