Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <stdio.h>
- #include <stdlib.h>
- #include "azonosit.h"
- //#define DEBUG
- enum State {bad, eleje, nemhash, alulvonas, nulla, szamok, V61, V62, karakterek, kisbetuk, karakterek2,
- m, mm, mme, mmes, mmese};
- // hamis, ha c linebreak karakter ( a . hoz )
- bool isOk(char c){
- return !(c == '\n' || c == '\r' || c == '\025');
- }
- int main(void){
- azonosit(6, false);
- int linecount = 0, matchcount = 0;
- State state = eleje;
- char currCh;
- while((currCh = getchar()) != EOF){
- switch(state){
- case bad:
- #ifdef DEBUG
- std::cout << "BAD: " << currCh << std::endl;
- #endif
- break;
- case eleje:
- #ifdef DEBUG
- std::cout << "eleje: " << currCh << std::endl;
- #endif
- if(currCh == '#') state = bad;
- else state = nemhash;
- break;
- case nemhash:
- #ifdef DEBUG
- std::cout << "nemhash: " << currCh << std::endl;
- #endif
- if(currCh == '_') state = alulvonas;
- else if(currCh == '0') state = nulla;
- else if(currCh >= '1' && currCh <= '9') state = szamok;
- else state = bad;
- break;
- case alulvonas:
- #ifdef DEBUG
- std::cout << "alulvonas: " << currCh << std::endl;
- #endif
- if(currCh == '0') state = nulla;
- else if(currCh >= '1' && currCh <= '9') state = szamok;
- else state = bad;
- break;
- case nulla:
- #ifdef DEBUG
- std::cout << "nulla: " << currCh << std::endl;
- #endif
- if(currCh >= '0' && currCh <= '9') state = szamok;
- else state = bad;
- break;
- case szamok:
- #ifdef DEBUG
- std::cout << "szamok: " << currCh << std::endl;
- #endif
- if(currCh >= '0' && currCh <= '9') state = szamok;
- else if(currCh == 'V') state = V61;
- else state = bad;
- break;
- case V61:
- #ifdef DEBUG
- std::cout << "V61: " << currCh << std::endl;
- #endif
- if(currCh == '6') state = V62;
- else state = bad;
- break;
- case V62:
- #ifdef DEBUG
- std::cout << "V62: " << currCh << std::endl;
- #endif
- if(isOk(currCh)) state = karakterek;
- else state = bad;
- break;
- case karakterek:
- #ifdef DEBUG
- std::cout << "karakterek: " << currCh << std::endl;
- #endif
- if(currCh >= 'a' && currCh <= 'z') state = kisbetuk;
- else if(isOk(currCh)) state = karakterek2;
- else state = bad;
- break;
- case kisbetuk:
- #ifdef DEBUG
- std::cout << "kisbetuk: " << currCh << std::endl;
- #endif
- if(currCh >= 'a' && currCh <= 'z') state = kisbetuk;
- else if(isOk(currCh)) state = karakterek2;
- else state = bad;
- break;
- case karakterek2:
- #ifdef DEBUG
- std::cout << "karakterek2: " << currCh << std::endl;
- #endif
- if(currCh == 'm') state = m;
- else if(isOk(currCh)) state = karakterek2;
- else state = bad;
- break;
- case m:
- #ifdef DEBUG
- std::cout << "mese: " << currCh << std::endl;
- #endif
- if(currCh == 'm') state = mm;
- else if(isOk(currCh)) state = karakterek2;
- else state = bad;
- break;
- case mm:
- if(currCh == 'e') state = mme;
- else if(isOk(currCh)) state = karakterek2;
- else state = bad;
- break;
- case mme:
- if(currCh == 's') state = mmes;
- else if(isOk(currCh)) state = karakterek2;
- else state = bad;
- break;
- case mmes:
- if(currCh == 'e') state = mmese;
- else state = karakterek2;
- break;
- case mmese:
- if(currCh == 'A' || currCh == 'b') matchcount++;
- else if(isOk(currCh)) state = karakterek2;
- else state = bad;
- break;
- }
- if(currCh == '\n'){
- //std::cout << "UJ" << std::endl;
- state = eleje;
- linecount++;
- }
- }
- std::cout << std::oct << linecount << "/" << std::oct << matchcount << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement