坑点(测试点2和测试点5)
题目没有读清,尝试的密码题目没有说不包括空格,所以要采用getline对用户尝试的密码进行获取
实现
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
int tryNum = 0, times,i;
string correctPw,temp;
vector<string> str;
cin >> correctPw >> tryNum;
getchar();
while(1){
//cin >> temp;
getline(cin,temp);
if (temp == "#") break;
str.push_back(temp);
}
times = tryNum < str.size() ? tryNum : str.size();
for (i = 0; i < times; i++)
{
if (i < tryNum && str[i] == correctPw)
{
cout << "Welcome in" << endl;
break;
}
else if (str[i] != correctPw)
cout << "Wrong password: " << str[i] << endl;
}
if(i==tryNum)
cout<< "Account locked" << endl;
return 0;
}