【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("%[^\n]",temp);
        if(temp[0]=='#'&&temp[1]=='\0') break;
        flag++;
        if(strcmp(temp,mima)==0){
            printf("Welcome in\n");break;
        }else{
            printf("Wrong password: %s\n",temp);
            if(flag==N) {
                printf("Account locked\n");break;
            }
        }
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/hebust/p/9496083.html
今日推荐