Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cstring>
- #define L int(1e5 + 5)
- using namespace std;
- char s[L];
- bool correct(char sym) {
- return (sym == ' ' || (sym >= 'a' && sym <= 'z') || (sym >= 'A' && sym <= 'Z'));
- }
- int main() {
- gets(s);
- int l = strlen(s), res = 0;
- bool open = false;
- for (int i = 0; i < l; i++) {
- if (s[i] == '(') {
- if (open) res++;
- open = true;
- }
- if (s[i] == ')') {
- if (open)
- open = false;
- else
- res++;
- }
- if (s[i] != '(' && s[i] != ')') {
- if (open) {
- if (!correct(s[i])) {
- open = false;
- res++;
- }
- }
- }
- }
- if (open) res++;
- printf("%d", res);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement