解题思路:不需要用while判断,最多也就只能错n次,n次内密码不对就不用管后面的了,所以可以用for循环来写
#include<bits/stdc++.h>
using namespace std;
int main(){
string s,s1;
int n;
cin>>s>>n;
getchar();//吃掉回车
for(int i=1;i<=n;i++){
getline(cin,s1);//输入的密码可能有空格
if(s1=="#")
return 0;
if(s1!=s)
cout<<"Wrong password: "<<s1<<endl;
else{
cout<<"Welcome in";
return 0;
}
}
cout<<"Account locked";
}