489 - Hangman Judge (UVA)

题目链接如下:

Online Judge

我的代码如下:

#include 
#include 
#include 
const int maxx = 1000;

int rnd, tot;
char a[maxx], b[maxx];
bool flag;

int main(){
    while(scanf("%d", &rnd) == 1 && rnd != -1){
        printf("Round %d\n", rnd);
        scanf("%s %s", a, b);
        tot = 7;
        std::set st;
        flag = false;
        for(int i = 0; i < strlen(a); ++i){
            st.insert(a[i]);
        }
        for(int i = 0; i < strlen(b); ++i){
            if(st.find(b[i]) != st.end()){
                st.erase(b[i]);
                if(st.empty()){
                    printf("You win.\n");
                    flag = true;
                    break;
                }
            } else{
                tot--;
                if(tot == 0){
                    printf("You lose.\n");
                    flag = true;
                    break;
                }
            }
        }
        if(flag){
            continue;
        }
        printf("You chickened out.\n");
    }
    return 0;
}

你可能感兴趣的:(UVA,c++)