解题代码
#include<string>
#include<iostream>
using namespace std;
int n, cnt;
bool flag;
string str, temp;
int main() {
cin >> str >> n;
getchar();
while (1) {
getline(cin, temp);
if (temp == "#") break;
if (flag) continue;
if (temp == str) {
cout << "Welcome in\n";
flag = true;
}
else {
cout << "Wrong password: " << temp << endl;
cnt++;
if (cnt == n) {
cout << "Account locked\n";
flag = true;
}
}
}
return 0;
}
测试结果
问题整理
1.基础题目。
2.注意输入的是一整行还是由分隔符分割的字符串。