TITLE:-
Remove Duplicates Recursively
PROBLEM:-
String S
Output string
1 <= |S| <= 10^3
where |S| represents the length of string
aabccba
abcba
xxxyyyzwwzzz
xyzwz
SOLUTION:-
#include <iostream>
using namespace std;
void removeConsecutiveDuplicates(char *input) {
/* Don't write main().
* Don't read input, it is passed as function argument.
* Change in the given string itself.
* No need to return or print anything
* Taking input and printing output is handled automatically.
*/
if(input[0]=='\0')
return;
if(input[0]!=input[1])
removeConsecutiveDuplicates(input+1);
else
{
int i=1;
for(;input[i]!='\0';i++)
{
input[i-1]=input[i];
}
input[i-1]=input[i];
removeConsecutiveDuplicates(input);
}
}
int main() {
char s[100000];
cin >> s;
removeConsecutiveDuplicates(s);
cout << s << endl;
}
This is dummy text. It is not meant to be read. Accordingly, it is difficult to figure out when to end it. But then, this is dummy text. It is not meant to be read. Period.
If you have any doubts then please let me know... ConversionConversion EmoticonEmoticon