Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int check_if_correct(const std::string& str) {
- std::vector<char> stack;
- for (size_t i = 0; i < str.length(); ++i) {
- if (str[i] == '(' || str[i] == '[' || str[i] == '{') {
- stack.push_back(str[i]);
- continue;
- }
- if (str[i] == ')') {
- if (stack.back() != '(') {
- return i;
- }
- stack.pop_back();
- continue;
- }
- if (str[i] == ']') {
- if (stack.back() != '[') {
- return i;
- }
- stack.pop_back();
- continue;
- }
- if (str[i] == '}') {
- if (stack.back() != '{') {
- return i;
- }
- stack.pop_back();
- continue;
- }
- }
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement