34 lines
643 B
C
34 lines
643 B
C
// https://bbc3502.hopto.org/c2021/index.php/home-17/591-1
|
|
#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;
|
|
int mismatch = 0;
|
|
for (int i = 0, n = strlen(str); i < n && !mismatch; i++) {
|
|
if (str[i] == '(') {
|
|
if (count < 0) { // )(
|
|
mismatch = 1;
|
|
} else {
|
|
count++;
|
|
}
|
|
} else if (str[i] == ')') {
|
|
count--;
|
|
}
|
|
}
|
|
|
|
// Validate
|
|
if (count != 0) {
|
|
printf("parentheses do not match!\n");
|
|
} else {
|
|
printf("parentheses match!\n");
|
|
}
|
|
return 0;
|
|
}
|