forked from HarshCasper/NeoAlgo
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPair-Star.cpp
39 lines (35 loc) · 822 Bytes
/
Pair-Star.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
"Copyright [2021] <Anshika Dubey>"
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 "*".
*/
#include <bits/stdc++.h>
void pairStar(char input[]) {
int size = 0, i;
while (input[size] != '\0')
size++;
if (input[0] == '\0' || size == 0)
return;
if (input[0] == input[1]) {
input[size+1] = '\0';
for (int i = size-1; i >= 1; i--) {
input[i+1] = input[i];
}
input[1] = '*';
pairStar(input+1);
} else {
pairStar(input+1);
}
}
int main() {
char input[100];
std::cin.getline(input, 100);
pairStar(input);
std::cout << input <<std:: endl;
}
/*
sample input:
hello
sample output:
hel*lo
Time complexity: O(n)
*/