Wednesday, 3 August 2016

Super Reduced String Hacker Rank Problem Solution.


Solution:

#include <bits/stdc++.h>
using namespace std;
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main() {

 string str;
 cin >> str;
 int len = str.length();
 for(int i = 0; i < len;){
        if(str[i] == str[i+1] && i > -1){
            str.erase(i,2);
            i--;
        }
        else i++;
 }

 if(!str.empty())cout << str << endl;
 else cout << "Empty String" << endl;
 return 0;
}

No comments:

Post a Comment