#include<iostream>
using namespace std;
int main(){
string rtpass,pass[10];
int n,cont = 0;
cin>>rtpass>>n;
getchar();
getline(cin,pass[0]);
while(pass[cont]!="#") {
getline(cin,pass[++cont]);
}
cont=0;
while(n!=0){
if(pass[cont]==rtpass){
cout<<"Welcome in"<<endl;
return 0;
}
else {
cout<<"Wrong password: "<<pass[cont]<<endl;
n--;
}
cont++;
}
if(n==0)cout<<"Account locked";
}

图片没贴出来
有bug,循环还要加个条件cont小于等于输入密码个数
修改如下,供参考:
#include<iostream>
#include<string>
using namespace std;
int main() {
string rtpass, pass, end = "#";
int n;
cin >> rtpass >> n;
getchar();
while (n) {
getline(cin, pass);//用户输入可能带空格
if (pass != end) {
if (pass == rtpass) {
cout << "Welcome in" << endl;
break;
}
else {
cout << "Wrong password: " << pass << endl;
n--;
}
}
else {
break;
}
}
if (n == 0) {
cout << "Account locked" << endl;
}
return 0;
}