Advertisement
Malinovsky239

пример на строки №2

Oct 23rd, 2011
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cstring>
  3.  
  4. #define L int(1e5 + 5)
  5.  
  6. using namespace std;
  7.  
  8. char s[L];
  9.  
  10. bool correct(char sym) {
  11.     return (sym == ' ' || (sym >= 'a' && sym <= 'z') || (sym >= 'A' && sym <= 'Z'));
  12. }
  13.  
  14. int main() {
  15.     gets(s);   
  16.     int l = strlen(s), res = 0;
  17.     bool open = false;
  18.  
  19.     for (int i = 0; i < l; i++) {
  20.         if (s[i] == '(') {
  21.             if (open) res++;
  22.             open = true;
  23.         }
  24.         if (s[i] == ')') {
  25.             if (open)
  26.                 open = false;
  27.             else
  28.                 res++;
  29.         }
  30.         if (s[i] != '(' && s[i] != ')') {
  31.             if (open) {
  32.                 if (!correct(s[i])) {
  33.                     open = false;
  34.                     res++;                 
  35.                 }
  36.             }
  37.         }
  38.     }
  39.  
  40.     if (open) res++;
  41.  
  42.     printf("%d", res);
  43.  
  44.     return 0;
  45. }
  46.  
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement