PAT-BASIC1067——试密码

我的PAT-BASIC代码仓:https://github.com/617076674/PAT-BASIC

原题链接:https://pintia.cn/problem-sets/994805260223102976/problems/994805266007048192

题目描述:

PAT-BASIC1067——试密码

知识点:字符串比较

思路:用compare函数比较字符串

对本题而言,时间复杂度和空间复杂度的分析意义不大。

C++代码:

#include<iostream>
#include<string>

using namespace std;

int main(){
	string password;
	int N;
	cin >> password >> N;
	
	getchar();
	string tempPassword;
	while(true){
		if(N-- == 0){
			cout << "Account locked" << endl;
			break;
		}
		getline(cin, tempPassword);
		if(tempPassword.compare("#") == 0){
			break;
		}else if(tempPassword.compare(password) == 0){
			cout << "Welcome in" << endl;
			break;
		}else {
			cout << "Wrong password: " << tempPassword << endl;
		}
	}
	
	return 0;
}

C++解题报告:

PAT-BASIC1067——试密码