【PAT】B1067 试密码(20 分)

注意读取时的换行符用getchar吸收
第十个错误后直接输出锁定

#include<cstdio>
#include<string.h>

int main(){
    char mima[100],temp[10000];int N,flag=0;
    scanf("%s %d",mima,&N); 
    while(1){
        getchar();
        scanf("%[^
]",temp);
        if(temp[0]=='#'&&temp[1]=='') break;
        flag++;
        if(strcmp(temp,mima)==0){
            printf("Welcome in
");break;
        }else{
            printf("Wrong password: %s
",temp);
            if(flag==N) {
                printf("Account locked
");break;
            }
        }
    }
    return 0;
}
原文地址:https://www.cnblogs.com/hebust/p/9496083.html