当前位置:网站首页>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;
}
边栏推荐
- 简单的数据库连接示例
- [Yugong series] March 2022 asp Net core Middleware - conditional routing
- Hudi of data Lake (14): basic concepts of Apache Hudi
- fastjson开启safeMode,关闭autoType,去除安全漏洞
- Oracle users and tablespaces
- Solution en cas de défaillance du script Unity
- PostgreSQL basic introduction and deployment
- [Bank Research Report] technology enabled retail finance carbon neutral development report (2022) - download link attached
- What is the difference between the gin framework of golang and the various methods of receiving parameters and various bindings?
- 顺序表与链表-----进阶
猜你喜欢

微信小程序項目實例——體質計算器

1186_ Accumulation of embedded hardware knowledge_ Triode and three electrodes

绝对定位使盒子居中显示的三种方式

Community Conference | the mosn community will release version 1.0 and promote the evolution of the next generation architecture

技术经济与企业管理 复习 第四章
![[Business Research Report] forward looking report on urban renewal and development in China in 2021 - download link attached](/img/5d/15615ad26dc3dbb10b0b9de8813848.jpg)
[Business Research Report] forward looking report on urban renewal and development in China in 2021 - download link attached

Exemple de projet d'applet Wechat - calculatrice de constitution

Demand and business model innovation - demand 11 - overview of demand analysis

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

Wechat applet project example - renju for two
随机推荐
Addition and multiplication of large integers;
Computer configuration suggestions for learning modeling
Concept and introduction of microservice
Demand and business model innovation - demand 10- observation and document review
laravel 8 选用 jwt 进行接口验证
Simple database connection example
How to modify the result name of MySQL query result 1 and result 2
[string] determine whether S2 is the rotation string 2 of S1
Cloud native overview
根據變換矩陣進行圖像拼接
[Yugong series] March 2022 asp Net core Middleware - current limiting
Youcans' opencv lesson - 10 Image restoration and reconstruction
Go syntax variable
Hudi of data Lake (14): basic concepts of Apache Hudi
Final summary of addition, deletion, modification and query
2020-12-06
In 2022, don't you know the difference between arrow function and ordinary function?
Experience the good team collaborative development process brought by Huawei cloud code hosting from 0 [my Huawei cloud experience journey] [play with Huawei cloud]
Solution en cas de défaillance du script Unity
Introduce the functions of the new project aleo