# 11966 - Parentheses Matching >author: Utin ###### tags: `STL` --- ## Brief See the code below ## Solution 0 ```cpp= #include <bits/stdc++.h> std::string str = "()[]{}<>"; int main() { std::stack<char> S; int T, i = 1; char c; bool ans = true; std::cin >> T; getchar(); // get the excess '\n' while(i <= T) { // get input c = getchar(); // check if the string is end if (c == '\n' || c == EOF) { std::cout << "Case " << i << ": " << ((ans && S.empty()) ? "Yes\n" : "No\n"); i++; ans = true; while (S.size()) S.pop(); } // if ans is false, we don't need to do anything else if (ans) { // left pare if (str.find(c) % 2 == 0) S.push(c); // empty + right pare else if (S.empty()) ans = false; // right pare matches the top of stack else if (str.find(c) - 1 == str.find(S.top())) S.pop(); // right pare doesn't match the top of stack else ans = false; } } } // By Utin ``` ## Reference