https://pintia.cn/problem-sets/994805260223102976/problems/994805266007048192
一开始用cin输入每个用户的输入密码,但是忘记考虑用户输入是可能包含空格的。题中只规定了正确密码没有空格之类。所以把cin换成是getline,getline之前的cin会保留一个结束符,所以要用一个getchar去接收掉那个结束符。
#include<iostream>
using namespace std;
int main() {
string str, temp;
int n, time=0, flag=1;
cin >> str >> n;
getchar();
while(1){
getline(cin, temp);
if(temp == "#"){
break;
}
if(flag==0){
continue;
}
if(temp != str){
cout << "Wrong password: " << temp << endl;
time ++;
if(time >= n){
flag=0;
cout << "Account locked" << endl;
}
}else{
flag=0;
cout << "Welcome in" << endl;
}
}
return 0;
}