-
Notifications
You must be signed in to change notification settings - Fork 111
/
solution.cpp
44 lines (33 loc) · 916 Bytes
/
solution.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
40
41
42
43
#include <bits/stdc++.h>
using namespace std;
// Implementation Part
string superReducedString(string s) {
// traversing all characters of string s
for(int i = 0; i < s.size(); ){
// checking if consecutive characters are same
if(s[i + 1] == s[i]){
// if same then delete the pair of same characters i.e ith and (i+1)th
// on deleting ith character first then new position of (i+1)th change to ith
s.erase(s.begin() + i);
s.erase(s.begin() + i);
// again start from 0, and check again
i = 0;
}else{
i++;
}
}
if(s.size() != 0)
return s;
else
return "Empty String";
}
int main()
{
ofstream fout(getenv("OUTPUT_PATH"));
string s;
getline(cin, s);
string result = superReducedString(s);
fout << result << "\n";
fout.close();
return 0;
}