matbensch

TetrisGenerationSolution

Mar 21st, 2022
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <set>
  4. #include <map>
  5. #include <string>
  6. #include <algorithm>
  7.  
  8. using namespace std;
  9.  
  10. int main() {
  11.  
  12.     map<char, int> mp = map<char, int>();
  13.     mp['J'] = 0;
  14.     mp['L'] = 1;
  15.     mp['S'] = 2;
  16.     mp['Z'] = 3;
  17.     mp['I'] = 4;
  18.     mp['O'] = 5;
  19.     mp['T'] = 6;
  20.  
  21.     int T;
  22.     cin >> T;
  23.     while (T-- > 0) {
  24.         string s;
  25.         cin >> s;
  26.  
  27.         int l = s.length();
  28.         vector<int> v = vector<int>(l);
  29.         for (int i = 0; i < l; i++) {
  30.             v[i] = mp[s[i]];
  31.         }
  32.  
  33.         bool pass = false;
  34.         for (int j = 0; j < 7; j++) {
  35.             bool current = true;
  36.             set<int> vals = set<int>();
  37.             for (int i = 0; i < j; i++) {
  38.                 vals.insert(v[i]);
  39.             }
  40.             if (vals.size() != j) {
  41.                 current = false;
  42.             } else {
  43.                 vals = set<int>();
  44.                 int counter = 0;
  45.                 for (int i = j; i < l; i++) {
  46.                     counter++;
  47.                     vals.insert(v[i]);
  48.                     if (counter == 7) {
  49.                         if (7 != vals.size()) {
  50.                             current = false;
  51.                             break;
  52.                         }
  53.                         counter = 0;
  54.                         vals = set<int>();
  55.                     }
  56.                 }
  57.                 if (vals.size() != counter) {
  58.                     current = false;
  59.                 }
  60.             }
  61.  
  62.             if (current) {
  63.                 pass = true;
  64.                 break;
  65.             }
  66.         }
  67.         if (pass) {
  68.             cout << 1 << endl;
  69.         } else {
  70.             cout << 0 << endl;
  71.         }
  72.     }
  73.     return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment