1067 试密码 (20 分)(测试点2、5错误原因)

在这里插入图片描述
题中说了第一行给出的密码不含空格,大部分就会想当然的认为用户输入的密码也不含空格,因此用getline获取一行的字符串可以避免2、5测试点错误。

#include <iostream>
#include <cstdio>
#include <string>
using namespace std;

int main(){
    
    
	string s;
	int n;
	cin >> s >> n;
	
	int cuowu = 0;
	bool end = false;
	getchar();
	while(1){
    
    
		string str;
		getline(cin,str);
		if(str == "#") break;
		if(!end){
    
    
			if(s != str){
    
    
				cuowu++;
				printf("Wrong password: %s\n", str.c_str());
				if(cuowu == n){
    
    	
					printf("Account locked\n");
					end = true;
				}
			}else{
    
    
				printf("Welcome in\n");
				end = true;
			}
		}
	}
	
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_45964844/article/details/113761199
今日推荐