注意空格,使用getline()输入
#include <iostream>
using namespace std;
int main()
{
string password, t;
int n, cnt = 0;
cin >> password >> n;
getchar();
while (1)
{
getline(cin, t);
if (t == "#")
{
break;
}
cnt++;
if (cnt <= n && t == password)
{
cout << "Welcome in";
break;
}
else if (cnt <= n && t != password)
{
cout << "Wrong password: " << t << endl;
if (cnt == n)
{
cout << "Account locked";
break;
}
}
}
return 0;
}