fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int closedBlock(char* value) {
  5. int closed = 0;
  6.  
  7. int i;
  8. for (i = 0; i < strlen(value); i++) {
  9. if ('{' == value[i]) {
  10. closed++;
  11. } else if ('}' == value[i]) {
  12. closed--;
  13. }
  14. }
  15.  
  16. return !closed;
  17. }
  18.  
  19. int main()
  20. {
  21. char teststring[] = "a a a a {a a a a { }";
  22. int close = closedBlock(teststring);
  23. printf("closed:%d\n",close);
  24. char teststring2[] = "a a a a {a a a a { }}";
  25. close = closedBlock(teststring2);
  26. printf("closed2:%d\n",close);
  27.  
  28. }
  29.  
Runtime error #stdin #stdout 0.01s 1676KB
stdin
Standard input is empty
stdout
closed:0
closed2:1