Untitled
unknown
plain_text
2 years ago
695 B
7
Indexable
#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;
}
}
Editor is loading...
Leave a Comment