Given a string S, compute recursively a new string where identical chars that are adjacent in the original string are separated from each other by a “*”.
Pair star
PROBLEM:- Given a string S, compute recursively a new string where identical chars that are adjacent in the original string are separated from each other by a “*”.
Input format: String S
Output format: Modified string
Constraints :0 <= |S| <= 1000 where |S| represents length of string S.
Sample Input 1 :hello
SOLUTION:-
#include <iostream>
using namespace std;
// Change in the given string itself. So no need to return or print the changed string.
#include<string.h>
void pairStar(char input[]) {
// Write your code here
if(strlen(input)==1)
return;
pairStar(input+1);
if(input[0]==input[1])
{
int i=strlen(input);
while(i>=1)
{
input[i+1]=input[i];
i--;
}
input[i+1]='*';
}
}
int main() {
char input[100];
cin.getline(input, 100);
pairStar(input);
cout << input << endl;
}