UVA 384 Slurpys 상태기 구현

4352 단어 UVA
옆집 녀석에게서 배운 사고방식은 아마도 이렇게 하면 좀 더 명확해질 것이다. 참고로 제공할 뿐이다.
#include 
#include 

using namespace std;

int main()
{
    char str[100000];
    int n;
    enum states {next_slimps,closing_slimps,next_slumps,new_slumps,f_ing,end_slumps,error};
    while(scanf("%d",&n)!=EOF)
    {
        printf("SLURPYS OUTPUT
"); while(n--) { cin>>str; int i=0,opened=0,closed=0,finish_slimps=0; char c=str[i]; states state=next_slimps; while(c!='\0') { switch (state) { case next_slimps: { if(c=='A') { state=next_slumps; opened++; break; } else { state=error; break; } } case closing_slimps: { if(opened!=closed) { if(c=='C') { closed++; break; } else { state=error; break; } } else { state=next_slumps; finish_slimps=1; i--; break; } } case next_slumps: { if(c=='D'||c=='E') { state=new_slumps; break; } else if(c=='B') { state=next_slimps; break; } else if(c=='H') { state=closing_slimps; closed++; break; } else { state=error; break; } } case f_ing: { if(c=='F') { break; } else if(c=='D'||c=='E') { state=new_slumps; break; } else if(c=='G') { state=end_slumps; break; } else { state=error; break; } } case new_slumps: { if(c=='F') { state=f_ing; break; } else { state=error; break; } } case end_slumps: { if(!finish_slimps) { closed++; state=closing_slimps; break; } else { state=error; break; } } } c=str[++i]; if(state==error) { goto print; } } print: if(state==end_slumps) { printf("YES
"); } else { printf("NO
"); } } printf("END OF OUTPUT
"); } return 0; }

좋은 웹페이지 즐겨찾기