lolamontes69

K+R Exercise1_24

Sep 5th, 2014
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.97 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5.     int c;
  6.     int PIN, POUT, BIN, BOUT, BRIN, BROUT, SQ, DQ;
  7.  
  8.     PIN = POUT = BIN = BOUT = BRIN = BROUT = SQ = DQ = 0;
  9.     while((c=getchar())!=EOF) {
  10.         if(c=='(') ++PIN;
  11.         if(c==')') ++POUT;
  12.         if(c=='[') ++BIN;
  13.         if(c==']') ++BOUT;
  14.         if(c=='{') ++BRIN;
  15.         if(c=='}') ++BROUT;
  16.         if(c=='"') ++DQ;
  17.         if(c=='\'') ++SQ;
  18.  
  19.         printf("%c",c);
  20.     }
  21.         if(PIN>POUT)   printf("\n Missing %d ')'s ",PIN-POUT);
  22.         if(POUT>PIN)   printf("\n Missing %d '('s ",POUT-PIN);
  23.         if(BIN>BOUT)   printf("\n Missing %d ']'s ",BIN-BOUT);
  24.         if(BIN<BOUT)   printf("\n Missing %d '['s ",BOUT-BIN);
  25.         if(BRIN>BROUT) printf("\n Missing %d '}'s ",BRIN-BROUT);
  26.         if(BRIN<BROUT) printf("\n Missing %d '{'s ",BROUT-BRIN);
  27.         if(DQ%2!=0)    printf("\n Missing '\"'s ");
  28.         if(SQ%2!=0)    printf("\n Missing \"'\"s ");
  29.         puts(" ");
  30.  
  31.  
  32.  
  33.     return(0);
  34. }
Advertisement
Add Comment
Please, Sign In to add comment