Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Mar 21st, 2010 | Syntax: C | Size: 2.07 KB | Hits: 52 | Expires: Never
Copy text to clipboard
  1. #include <stdio.h>
  2. typedef enum {wait,barmi,nemkereszt,vonal,nulla,nullax,digit,W,W6,q,qq,qqr,qqri,qqriq} allapotok;
  3.  
  4. int main() {
  5.  
  6. int sor=0,jo=0,ch,seged=0;
  7. allapotok allapot=barmi;
  8.  
  9. while((ch=getchar())!=EOF) {
  10.         switch(allapot) {
  11.                 case wait:              if(ch=='\n'){sor++;allapot=barmi;} break;
  12.                 case barmi:             if (ch!='#'&& ch!='\n') allapot=nemkereszt;else if(ch=='\n'){sor++;allapot=wait;} else allapot=wait;seged=0; break;
  13.                 case nemkereszt:        if (ch=='-') allapot=vonal;else if (ch=='0') allapot=nulla;else if(ch>='0'&&ch<='9')allapot=digit;else if(ch=='W')allapot=W;else if(ch=='\n'){sor++;allapot=barmi;}else allapot=wait;   break;
  14.                 case vonal:             if (ch=='0') allapot=nulla; else if (ch>='0'&&ch<='9') allapot=digit; else if(ch='W')allapot=W;else if(ch=='\n'){sor++;allapot=barmi;} else allapot=wait;  break;                                              
  15.                 case nulla:             if (ch=='x')allapot=nullax; else if (ch>='0'&&ch<='9') allapot=digit;else if(ch=='W')allapot=W;else if(ch=='\n'){sor++;allapot=barmi;} else allapot=wait;break;                                        
  16.                 case nullax:            if (ch>='0'&&ch<='9') allapot=digit;else if(ch=='W')allapot=W;else if(ch=='\n'){sor++;allapot=barmi;} else allapot=wait; break;
  17.                 case digit:             if (ch>='0'&&ch<='9') allapot=digit;    else if (ch=='W') allapot=W;else if(ch=='\n'){sor++;allapot=barmi;}else allapot=wait;break;                                            
  18.                 case W:                 if (ch=='6') allapot=W6;else if(ch=='\n'){sor++;allapot=barmi;} else allapot=wait;break;                                               
  19.                 case W6:                if (ch=='q'&& seged==1)allapot=q; else if(ch=='\n'){sor++;allapot=barmi;}seged=1; break;
  20.                 case q:                 if (ch=='q') allapot=qq;else if(ch=='\n'){sor++;allapot=barmi;} else allapot=W6;        break;
  21.                 case qq:                if (ch=='r') allapot=qqr;else if(ch=='\n'){sor++;allapot=barmi;}else if(ch=='q')allapot=qq; else allapot=W6; break;
  22.                 case qqr:               if (ch=='i') allapot=qqri;else if(ch=='\n'){sor++;allapot=barmi;} else allapot=W6; break;
  23.                 case qqri:              if (ch=='q') allapot=qqriq;else if(ch=='\n'){sor++;allapot=barmi;} else allapot=W6;     break;
  24.                 case qqriq:             if(ch=='a' || ch=='B') {allapot=wait;jo++;}else if(ch=='\n'){sor++;allapot=barmi;}      else allapot=W6; break;
  25.                 }}
  26.                 printf("%o/%o\n",sor,jo);
  27.                 return 0;}