My omnium-gatherom of scripts and source code.
1/* ========================================================================
2 *
3 * Filename:
4 * Description:
5 * Author:
6 * Version: 0.0.1
7 *
8 * ======================================================================== */
9#include <iostream>
10#include <string>
11#include <stack>
12
13auto isValid(std::string s) -> bool;
14
15auto main() -> int
16{
17 std::cout << isValid("()") << std::endl;
18 return 0;
19}
20
21auto isValid(std::string s) -> bool
22{
23 auto st = std::stack<char>();
24
25 for (const auto& ch : s) {
26 char check = '\0';
27 switch (ch) {
28 case '(':
29 case '{':
30 case '[':
31 st.push(ch);
32 continue;
33 case ')':
34 check = '(';
35 break;
36 case '}':
37 check = '{';
38 break;
39 case ']':
40 check = '[';
41 break;
42 default: continue;
43 }
44 if (not st.empty()) {
45 if (st.top() == check)
46 st.pop();
47 else
48 return false;
49 } else {
50 return false;
51 }
52
53
54 }
55
56 return st.empty();
57}