我的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——试密码

 

相关文章:

  • 2021-11-24
  • 2022-12-23
  • 2021-05-11
  • 2021-04-07
  • 2021-10-16
  • 2021-05-18
  • 2021-10-05
  • 2021-05-23
猜你喜欢
  • 2022-12-23
  • 2021-10-27
  • 2021-09-15
  • 2021-04-30
  • 2021-12-06
  • 2021-09-07
  • 2022-01-15
相关资源
相似解决方案