1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
| #include<algorithm> #include<cstdio> #include<cstring> #include<iostream> #include<map> #include<string> #include<vector> using namespace std; typedef pair<int, int> pii; struct node{ vector<int> sz; vector<pii> qj; bool operator == (const node &a){ if (sz != a.sz || qj != a.qj){ return false; } else{ return true; } } node operator += (const node &a){ sz.insert(sz.end(), a.sz.begin(), a.sz.end()); return *this; } bool judge(){ vector<int> s = sz; sort(s.begin(), s.end()); return unique(s.begin(), s.end()) - s.begin() == 1; } void sort_node(){ sort(sz.begin(), sz.end()); } void print(){ printf("__________________________\n"); for (auto i:sz){ printf("%d ", i); } printf("\n_________________________\n"); } }; inline int find_r (char *s, const int &l, const int &len){ int lcnt = 0, rcnt = 0; for (int i = l; i < len; i++){ if (s[i] == '('){ lcnt++; } else if (s[i] == ')'){ rcnt++; if (lcnt == rcnt){ return i; } } } } inline node get (char *s, const int &l, const int &r, const int &len){ node ans; int x = 0, flag = 0; for (int i = l; i < r; i++){ if (s[i] == '['){ flag = 1; } else if (s[i] >= '0' && s[i] <= '9'){ x = 10 * x + (s[i] ^ 48); } else if (flag){ if (s[i] == ']'){ flag = 0; } ans.sz.push_back(x); x = 0; } } return ans; } inline node deal(char* s, int &pos, const int &len){ node ans; int x = 0, flag = 0; for (int i = 0; i < len; i++){ if (s[i] == 's' && s[i + 1] == 'o'){ i += 6; int r = find_r(s, i, len); node temp = get(s, i, r, len); temp.sort_node(); ans += temp; i = r; } else if (s[i] == 's' && s[i + 1] == 'h'){ i += 7; int r = find_r(s, i, len); node temp = get(s, i, r, len); temp.sort_node(); if (!temp.judge()){ ans.qj.push_back(make_pair(ans.sz.size(), ans.sz.size() + temp.sz.size())); } ans += temp; i = r; } if (s[i] == '['){ flag = 1; } else if (s[i] >= '0' && s[i] <= '9'){ x = 10 * x + (s[i] ^ 48); } else if (flag){ if (s[i] == ']'){ flag = 0; } ans.sz.push_back(x); x = 0; } } return ans; } char s1[1000009], s2[1000009]; int main(){ scanf("%s", s1); scanf("%s", s2); int pos = 0, len1 = strlen(s1), len2 = strlen(s2); node a = deal(s1, pos, len1); pos = 0; node b = deal(s2, pos, len2); if (a == b){ printf("equal"); } else{ printf("not equal"); } return 0; }
|