BUPT-homework/semester1/pset12/2-1-paren.c
2021-12-05 12:16:06 +08:00

30 lines
611 B
C

// https://bbc3502.hopto.org/c2021/index.php/home-17/591-1
// This code should get 100 points but due to the shitty pintia, it gets 90.
#include <stdio.h>
#include <string.h>
#define MAXLEN 101
int main(void) {
char str[MAXLEN];
// fgets is not gets
fgets(str, MAXLEN, stdin);
// Process string
int count = 0;
for (int i = 0, n = strlen(str); i < n; i++) {
if (str[i] == '(') {
count++;
} else if (str[i] == ')') {
count--;
}
}
// Validate
if (count != 0) {
printf("parentheses do not match!\n");
} else {
printf("parentheses match!\n");
}
return 0;
}