# 13533 - Parentheses Matching 2 >author: Utin ###### tags: `STL` --- ## Brief See the code below ## Solution 0 ```cpp= #include <bits/stdc++.h> std::string str = "()[]{}<>sm"; int main() { std::string input; while (std::getline(std::cin, input)) { std::stack<char> S; bool ans = true; for (int i = 0; i < input.size(); i++) { if (ans) { if (str.find(input[i]) % 2 == 0) S.push(input[i]); else if (S.empty()) ans = false; else if (str.find(input[i]) - 1 == str.find(S.top())) S.pop(); else ans = false; } } std::cout << ((ans && S.empty()) ? "SM\n" : "MS\n"); } } // By Utin ``` ## Reference
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up