Advertisement
Guest User

Untitled

a guest
Mar 1st, 2015
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.01 KB | None | 0 0
  1.  
  2. #include<stdio.h>
  3. int i = 0;
  4.  
  5. main()
  6. {
  7.  
  8.         char input[99];
  9.  
  10.         printf (" type a string: ");
  11.         scanf("%s", input);
  12.         printf ("word: %s\n", input);
  13.  
  14.         if (startCheck(input)) {
  15.                 printf("ACCEPTED");
  16.         }
  17.         else {
  18.                 printf("REJECTED");
  19.         }
  20.  
  21.  
  22.  
  23.         return 0;
  24. }
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31. int checkB(char* input) {
  32.         if (input[i] == '\n' || input[i] == '\0') return 1;
  33.         char peek = input[i];
  34.         if (peek == '&' ||
  35.                 peek == '|' ||
  36.                 peek == ':' ||
  37.                 peek == '-') {
  38.                 i++;
  39.                 return 1;
  40.         }
  41.         return 0;
  42.  
  43.  
  44. }
  45.  
  46. int checkS(char* input) {
  47.         if (input[i] == '\n' || input[i] == '\0') return 1;
  48.         char peek = input[i];
  49.         if (peek == '0' ||
  50.                 peek == '1' ||
  51.                 peek == 'q' ||
  52.                 peek == 'p') {
  53.                 i++;
  54.                //if (!checkS(input) && !checkB(input) && input[i] !='(')return 0;
  55.                        //  if(input[i] != '!')return 0;
  56.                           //  if(input[i] != '(')return 0;
  57.                               // if(input[i] != ')')return 0;
  58.                                   //  if(!checkB(input))return 0;
  59.                 }
  60.  
  61.         else if (peek == '!') {
  62.                 i++;
  63.                 if (!checkS(input)) return 0;
  64.         }
  65.         else if (peek == '(') {
  66.                 i++;
  67.                 if (!checkS(input)) return 0;
  68.                 if (!checkB(input)) return 0;
  69.                 if (!checkS(input)) return 0;
  70.  
  71.                 char peek2 = input[i];
  72.                 if (peek2 == ')') {
  73.                         i++;
  74.                         if (!checkB(input) && input[i] != ')') return 0;
  75.                 }
  76.                 else {
  77.                         return 0;
  78.                 }
  79.         }
  80.         else {
  81.                 return 0;
  82.         }
  83.         return 1;
  84. }
  85.  
  86.  
  87. int startCheck(char* input) {
  88.         return checkS(input);
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement