Guest User

Untitled

a guest
Jan 22nd, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1.  
  2. /* MIPT, task # 008
  3. "Brackets"
  4. 13.09.2011
  5. */
  6.  
  7. #include <stdio.h>
  8.  
  9. #define MAX_STR_LENGTH 4000
  10.  
  11. int main()
  12. {
  13. char s[MAX_STR_LENGTH];
  14.  
  15. gets (s);
  16.  
  17. int balance = 0;
  18. char *cur = s;
  19. while (*cur) {
  20. if ('(' == *cur) {
  21. ++balance;
  22. } else {
  23. --balance;
  24. }
  25. if (balance < 0) {
  26. puts ("NO");
  27. exit (0);
  28. }
  29. ++cur;
  30. }
  31.  
  32. if (!balance) {
  33. puts ("YES");
  34. } else {
  35. puts ("NO");
  36. }
  37.  
  38. return 0;
  39. }
Add Comment
Please, Sign In to add comment