当前位置:网站首页>Pat class B 1067 trial password (20 points)
Pat class B 1067 trial password (20 points)
2022-06-12 03:33:00 【myriadddddd】
When you try to log in to a system and forget your password , The system will generally only allow you to try a limited number of times , When the allowed number of times is exceeded , The account will be locked . This topic asks you to realize this small function .
Input format :
Enter a password on the first line ( Length not exceeding 20 Of 、 No spaces 、Tab、 Non empty string of carriage return ) And a positive integer N(≤10), They are the correct password and the number of attempts allowed by the system . Then each line gives a non empty string ending with carriage return , Is the password the user tried to enter . Input guarantees at least one attempt . When you read a single line # Character time , End of input , And this line is not user input .
Output format :
Every input to the user , If the password is correct and the number of attempts does not exceed N, Output in one line Welcome in, And end the program ; If it's wrong , Then output in one line in format Wrong password: Wrong password entered by the user ; When the wrong attempt reaches N When the time , One more line Account locked, And end the program .
sample input 1:
Correct%pw 3
correct%pw
[email protected]
whatisthepassword!
Correct%pw
#
sample output 1:
Wrong password: correct%pw
Wrong password: [email protected]
Wrong password: whatisthepassword!
Account locked
sample input 2:
[email protected] 3
[email protected]
[email protected]
[email protected]
try again
#
sample output 2:
Wrong password: [email protected]
Wrong password: [email protected]
Welcome in
analysis :
Note that the number of times the input threshold is reached is output first Wrong password Then the output Account locked.
Code :
#include <iostream>
using namespace std;
int main() {
string pwd, test = "";
int times, i = 0;
cin >> pwd >> times;
getchar(); // buffer
while (true) {
getline(cin, test);
if (test == "#") // End input
break;
i++;
if (i <= times && test == pwd) { // The number of tests is less than the threshold and the password is incorrect
cout << "Welcome in" << endl;
break;
} else if (i <= times && test != pwd) { // The number of tests is less than the threshold and the password is correct
cout << "Wrong password: " << test << endl;
if (i == times) { // The number of tests reached the threshold ,
cout << "Account locked" << endl;
break;
}
}
}
return 0;
}
边栏推荐
- Demand and business model innovation - demand 8- interview
- sed命令
- Wechat applet project example - Fitness calculator
- tcp 三次握手与四次挥手
- Recommend 6 office software, easy to use and free, double the efficiency
- Youcans' opencv lesson - 10 Image restoration and reconstruction
- $LastExitCode=0, but $?= False in PowerShell. Redirecting stderr to stdout gives NativeCommandError
- Data flow diagram of Flink
- 云原生概述
- Requirements and business model analysis requirements 13 data modeling
猜你喜欢

如何修改mysql 查询出来的结果名称 结果1,结果2

Evolution and practice of Unicom real-time computing platform

【鸿蒙】 使用定时器做一个简单的抢红包小游戏

Demand and business model innovation - demand 8- interview
![[C language] dynamic memory allocation](/img/ac/ba3882c76f93dde0ab0d5294c5b6d9.jpg)
[C language] dynamic memory allocation

Mysql/oracle takes the unique time as the boundary, and the sum is less than or equal to this time, and greater than this time

顺序表与链表-----进阶

分数大小的比较

Domestic mobile phones are snubbing low-end consumers, and Nokia provides them with high-quality products
![[Hongmeng] use the timer to play a simple game of robbing red envelopes](/img/27/32b65dc90db7f6ece24ad39ff9b0ef.png)
[Hongmeng] use the timer to play a simple game of robbing red envelopes
随机推荐
go 递归无限极分类
Inverted string - two solutions
Batch automated e-mail: Vika Vige table x Tencent Qianfan scene connector has made new moves, and business communication and event marketing only need 3 steps
vim命令大全
微信小程序项目实例——双人五子棋
Mysql/oracle takes the unique time as the boundary, and the sum is less than or equal to this time, and greater than this time
PostMessage implements window communication
Oracle schema object
Message queuing overview
Go syntax variable
Go recursive infinite classification
简单的数据库连接示例
[Hongmeng] use the timer to play a simple game of robbing red envelopes
laravel 8 选用 jwt 进行接口验证
postgresql基本介绍以及部署使用
2020-12-17
分数大小的比较
UI consistency design of products
PostgreSQL basic introduction and deployment
MySQL的check约束数字问题