Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "paren_recur.h"
- bool paren(void) {
- int c;
- for (c = getchar(); c != EOF; c = getchar()) {
- if ((unsigned char) c == '(') {
- if (paren()) continue;
- printf(") not appear\n");
- return false;
- }
- if ((unsigned char) c == '{') {
- if (brace()) continue;
- printf("} not appear\n");
- return false;
- }
- if ((unsigned char) c == ')') return true;
- if ((unsigned char) c == '}') {
- printf("(} mismatch\n");
- return false;
- }
- }
- return false;
- }
- bool brace(void) {
- int c;
- for (c = getchar(); c != EOF; c = getchar()) {
- if ((unsigned char) c == '(') {
- if (paren()) continue;
- printf(") not appear\n");
- return false;
- }
- if ((unsigned char) c == '{') {
- if (brace()) continue;
- printf("} not appear\n");
- return false;
- }
- if ((unsigned char) c == ')') {
- printf("{) mismatch\n");
- return false;
- }
- if ((unsigned char) c == '}') return true;
- }
- return false;
- }
- int main(int ac, char **av) {
- int c;
- for (c = getchar(); c != EOF; c = getchar()) {
- if ((unsigned char) c == '(') {
- if (paren()) continue;
- printf("() unmatch\n");
- return EXIT_FAILURE;
- }
- if ((unsigned char) c == '{') {
- if (brace()) continue;
- printf("{} unmatch\n");
- return EXIT_FAILURE;
- }
- }
- printf("(){} match\n");
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement