Advertisement
mickypinata

ICPC-T02935: Subway Tree Systems

Dec 7th, 2021
730
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. string sortCode(string &str){
  5.     vector<string> chd;
  6.     string tmp = "";
  7.     int cnt = 0;
  8.     for(int i = 1; i < (int)str.size() - 1; ++i){
  9.         char c = str[i];
  10.         if(c == '0'){
  11.             ++cnt;
  12.         } else {
  13.             --cnt;
  14.         }
  15.         tmp += c;
  16.         if(cnt == 0){
  17.             chd.push_back(sortCode(tmp));
  18.             tmp = "";
  19.         }
  20.     }
  21.     sort(chd.begin(), chd.end());
  22.     string ret = "0";
  23.     for(string &s : chd){
  24.         ret += s;
  25.     }
  26.     return ret + '1';
  27. }
  28.  
  29. int main(){
  30.  
  31.     int Q;
  32.     scanf("%d", &Q);
  33.     while(Q--){
  34.         string strA, strB;
  35.         cin >> strA >> strB;
  36.         strA = '0' + strA + '1';
  37.         strB = '0' + strB + '1';
  38.         if(sortCode(strA) == sortCode(strB)){
  39.             cout << "same\n";
  40.         } else {
  41.             cout << "different\n";
  42.         }
  43.     }
  44.  
  45.     return 0;
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement