Created
August 9, 2018 08:58
-
-
Save omniasaleh/1ef95c737ed171a4d034f6081722f2c1 to your computer and use it in GitHub Desktop.
1261 String Popping
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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