Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include<vector>
- #include<algorithm>
- #include<sstream>
- using namespace std;
- string vtos(const vector<char>& vec){
- stringstream s;
- for(int i=0;i<vec.size();i++){
- s << vec[i];
- }
- return s.str();
- }
- string reduced(const string& st)
- {
- vector<char> strin;
- for(int i=0;i<st.size();){
- if(st[i]==st[i+1])
- i=i+2;
- else
- {
- strin.push_back(st[i]);
- i++;
- }
- }
- return vtos(strin);
- }
- bool is_reducable(const string& s)
- {
- for(int i=0;i<s.size();i++){
- if(s[i]==s[i+1])
- return true;
- }
- return false;
- }
- int main()
- {
- string st;
- cin >> st;
- while(is_reducable(st))
- {
- st = reduced(st);
- }
- if(st.size()==0)
- cout << "Empty String"<<endl;
- else
- cout << st << endl;
- }
Add Comment
Please, Sign In to add comment