-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPairStar.cpp
More file actions
64 lines (48 loc) · 1014 Bytes
/
Copy pathPairStar.cpp
File metadata and controls
64 lines (48 loc) · 1014 Bytes
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
Title: Pair Star
Problem statement
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 "*".
Detailed explanation ( Input/output format, Notes, Images )
Input format :
String S
Output format :
Modified string
Constraints :
0 <= |S| <= 1000
where |S| represents length of string S.
Sample Input 1 :
hello
Sample Output 1:
hel*lo
Sample Input 2 :
aaaa
Sample Output 2 :
a*a*a*a
*/
#include<iostream>
using namespace std;
void PairStar(char input[]) {
if(input[0] == '\0') {
return;
}
PairStar(&input[1]);
if(input[0] == input[1]) {
int count = 0;
while(input[count] != '\0') {
count++;
}
while(count > 0) {
input[count+1] = input[count];
count--;
}
input[1] = '*';
}
return;
}
int main() {
char input[100];
cin.getline(input, 100);
PairStar(input);
cout << input << endl;
}