Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <string>
- #include <fstream>
- bool is_correct_bracket_seq(const std::string& str) {
- std::vector<char> vec;
- for (auto a : str) {
- if (a == '(' || a == '{' || a == '[') {
- vec.push_back(a);
- }
- if (a == ')') {
- if (vec.empty() || vec.back() != '(') {
- return false;
- }
- vec.pop_back();
- }
- if (a == ']') {
- if (vec.empty() || vec.back() != '[') {
- return false;
- }
- vec.pop_back();
- }
- if (a == '}') {
- if (vec.empty() || vec.back() != '{') {
- return false;
- }
- vec.pop_back();
- }
- }
- if (!vec.empty()) {
- return false;
- }
- return true;
- }
- int main() {
- std::ifstream fin("input.txt");
- std::string str;
- fin >> str;
- is_correct_bracket_seq(str) ? std::cout << "True" : std::cout << "False";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement