View Code of Problem 3913

#include <stdio.h>

int main(void) {
  int start = 0, count = 0, matches = 1;
  char c;

  for (;;) {
    c = getchar();
    if (c == '(') {
      start = 1;
      count++;
    } else if (c == ')') {
      start = 1;
      count--;
      if (count < 0) {
        matches = 0;
      }
    } else {
      if (start) {
        puts(count == 0 && matches == 1? "Yes": "No");
      }
      if (c == EOF) {
        break;
      }
      start = 0;
      count = 0;
      matches = 1;
    }
  }

  return 0;
}

Double click to view unformatted code.


Back to problem 3913