Skip to content

Instantly share code, notes, and snippets.

@omniasaleh
Created August 9, 2018 08:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save omniasaleh/1ef95c737ed171a4d034f6081722f2c1 to your computer and use it in GitHub Desktop.
Save omniasaleh/1ef95c737ed171a4d034f6081722f2c1 to your computer and use it in GitHub Desktop.
1261 String Popping
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <sstream>
#include <cstring>
#include<map>
using namespace std;
map<string, int>mp;
int solve(string s) {
if (s == "")
return 1;
if (mp.count(s))
return mp[s];
int i, j;
int ret = false;
for ( i = 0; i < s.size(); ++i) {
for (j = i; j < s.size(); ++j)
if (s[i] != s[j])break;
if (j >= i + 2) {
string sub = s.substr(0, i) + s.substr(j);
ret = ret | solve(sub);
i = j-1;
}
}
return mp[s]=ret;
}
int main(){
int t;
cin >> t;
string s;
while (t--) {
cin >> s;
cout << solve(s) << endl;;
}
system("pause");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment