Advertisement
Guest User

Untitled

a guest
Mar 18th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include "azonosit.h"
  6.  
  7. //#define DEBUG
  8.  
  9. enum State {bad, eleje, nemhash, alulvonas, nulla, szamok, V61, V62, karakterek, kisbetuk, karakterek2,
  10.     m, mm, mme, mmes, mmese};
  11.  
  12. // hamis, ha c linebreak karakter ( a . hoz )
  13. bool isOk(char c){
  14.     return !(c == '\n' || c == '\r' || c == '\025');
  15. }
  16.  
  17. int main(void){
  18.     azonosit(6, false);
  19.  
  20.     int linecount = 0, matchcount = 0;
  21.  
  22.     State state = eleje;
  23.  
  24.     char currCh;
  25.  
  26.     while((currCh = getchar()) != EOF){
  27.  
  28.         switch(state){
  29.             case bad:
  30. #ifdef DEBUG
  31.     std::cout << "BAD: " << currCh << std::endl;
  32. #endif
  33.             break;
  34.             case eleje:
  35. #ifdef DEBUG
  36.     std::cout << "eleje: " << currCh << std::endl;
  37. #endif
  38.                 if(currCh == '#') state = bad;
  39.                 else state = nemhash;
  40.             break;
  41.             case nemhash:
  42. #ifdef DEBUG
  43.     std::cout << "nemhash: " << currCh << std::endl;
  44. #endif
  45.                 if(currCh == '_') state = alulvonas;
  46.                 else if(currCh == '0') state = nulla;
  47.                 else if(currCh >= '1' && currCh <= '9') state = szamok;
  48.                 else state = bad;
  49.             break;
  50.             case alulvonas:
  51. #ifdef DEBUG
  52.     std::cout << "alulvonas: " << currCh << std::endl;
  53. #endif
  54.                 if(currCh == '0') state = nulla;
  55.                 else if(currCh >= '1' && currCh <= '9') state = szamok;
  56.                 else state = bad;
  57.             break;
  58.             case nulla:
  59. #ifdef DEBUG
  60.     std::cout << "nulla: " << currCh << std::endl;
  61. #endif
  62.                 if(currCh >= '0' && currCh <= '9') state = szamok;
  63.                 else state = bad;
  64.             break;
  65.             case szamok:
  66. #ifdef DEBUG
  67.     std::cout << "szamok: " << currCh << std::endl;
  68. #endif
  69.                 if(currCh >= '0' && currCh <= '9') state = szamok;
  70.                 else if(currCh == 'V') state = V61;
  71.                 else state = bad;
  72.             break;
  73.             case V61:
  74. #ifdef DEBUG
  75.     std::cout << "V61: " << currCh << std::endl;
  76. #endif
  77.                 if(currCh == '6') state = V62;
  78.                 else state = bad;
  79.             break;
  80.             case V62:
  81. #ifdef DEBUG
  82.     std::cout << "V62: " << currCh << std::endl;
  83. #endif
  84.                 if(isOk(currCh)) state = karakterek;
  85.                 else state = bad;
  86.             break;
  87.             case karakterek:
  88. #ifdef DEBUG
  89.     std::cout << "karakterek: " << currCh << std::endl;
  90. #endif
  91.                 if(currCh >= 'a' && currCh <= 'z') state = kisbetuk;
  92.                 else if(isOk(currCh)) state = karakterek2;
  93.                 else state = bad;
  94.             break;
  95.             case kisbetuk:
  96. #ifdef DEBUG
  97.     std::cout << "kisbetuk: " << currCh << std::endl;
  98. #endif
  99.                 if(currCh >= 'a' && currCh <= 'z') state = kisbetuk;
  100.                 else if(isOk(currCh)) state = karakterek2;
  101.                 else state = bad;
  102.             break;
  103.             case karakterek2:
  104. #ifdef DEBUG
  105.     std::cout << "karakterek2: " << currCh << std::endl;
  106. #endif
  107.                 if(currCh == 'm') state = m;
  108.                 else if(isOk(currCh)) state = karakterek2;
  109.                 else state = bad;
  110.             break;
  111.             case m:
  112. #ifdef DEBUG
  113.     std::cout << "mese: " << currCh << std::endl;
  114. #endif
  115.                 if(currCh == 'm') state = mm;
  116.                 else if(isOk(currCh)) state = karakterek2;
  117.                 else state = bad;
  118.             break;
  119.             case mm:
  120.                 if(currCh == 'e') state = mme;
  121.                 else if(isOk(currCh)) state = karakterek2;
  122.                 else state = bad;
  123.             break;
  124.             case mme:
  125.                 if(currCh == 's') state = mmes;
  126.                 else if(isOk(currCh)) state = karakterek2;
  127.                 else state = bad;
  128.             break;
  129.             case mmes:
  130.                 if(currCh == 'e') state = mmese;
  131.                 else state = karakterek2;
  132.             break;
  133.             case mmese:
  134.                 if(currCh == 'A' || currCh == 'b') matchcount++;
  135.                 else if(isOk(currCh)) state = karakterek2;
  136.                 else state = bad;
  137.             break;
  138.         }
  139.  
  140.         if(currCh == '\n'){
  141.             //std::cout << "UJ" << std::endl;
  142.             state = eleje;
  143.             linecount++;
  144.         }
  145.     }
  146.  
  147.     std::cout << std::oct << linecount << "/" << std::oct << matchcount << std::endl;
  148.  
  149.     return 0;
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement