Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
695 B
1
Indexable
Never
#include <iostream>
#include <string>

using namespace std;

int main() {
    string str;
    cin >> str;

    int count = 0;
    int open = 0;
    int close = 0;

    for (char ch : str) {
        if (ch == '(') {
            open++;
        }
        else if (ch == ')') {
            close++;
            if (open > 0) {
                count++;
                open--;
                close--;
            }
        }
    }

    cout << "Кол-во пар: " << count << std::endl;

    if (open == 0 && close == 0) {
        cout << "Скобки парные" << endl;
    }
    else {
        cout << "Скобки не парные" << endl;
    }
}
Leave a Comment