当前位置:网站首页>PAT B1067
PAT B1067
2022-06-25 19:57:00 【Madness makes freedom】
1067 Try password (20 branch )
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 inThere are several points to note in this question !!!!
- Enter the first string , Use cin Input , Because the string input is followed by the input times .
- For the answer entered by the user later , It is necessary to use getline Function input , Because the title only says the non empty string that has ended with carriage return , So there may be a space in the middle , By experiment , It is true that the data is composed of spaces . I used it at first cin Input .
- For the last output , There is one caveat , When the number of input errors reaches the required number ; Then you will output
Account locked
Can't wait for n+1 And then enter again , Otherwise, a set of data will fail , Here is the code to understand . That is the third code . At first I never understood , I think it's OK to write like this . Until I read the title , Just gradually understand .
I have written two codes in total , In fact, it's the same . Why write two , The first is input and then output , The second is to input all the data before processing . When I run the first code , My compiler can't pass , Although in PAT There is only one wrong group on the , The one mentioned above . But I have OCD , You have to see the result to calm down .
This is what I changed later , Code that can pass all !!!
#include <iostream>
#include <string>
using namespace std;
int main()
{
string correct,user_cin;
int n,count=0;
cin >> correct >> n;
getchar();
while(1)
{
++count;
//cin >> user_cin;
getline(cin,user_cin);
if(user_cin=="#")
{
break;
}
if(user_cin==correct)
{
cout << "Welcome in\n";
break;
}
else
{
cout << "Wrong password: " << user_cin << endl ;
if(count==n)
{
cout << "Account locked\n";
break;
}
}
}
return 0;
}This is the code for unified processing after all inputs !
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
string correct,in;
string user_cin[100];
int n,count=0,i=0;
cin >> correct >> n;
getchar();
while(getline(cin,in))
user_cin[i++]+=in;
for(int j=0;j<i;++j)
{
++count;
if(user_cin[j]=="#")
{
break;
}
if(count<=n)
{
if(user_cin[j]==correct)
{
cout << "Welcome in\n";
break;
}
else
{
cout << "Wrong password: " << user_cin[j] << endl ;
if(count==n)
{
cout << "Account locked\n";
break;
}
}
}
}
return 0;
}This is the first time that a set of data failed to pass the code !!
#include <iostream>
#include <string>
using namespace std;
int main()
{
string correct,user_cin;
int n,count=0;
cin >> correct >> n;
getchar();
while(1)
{
++count;
//cin >> user_cin;
getline(cin,user_cin);
if(user_cin=="#")
{
break;
}
if(count<=n)
{
if(user_cin==correct)
{
cout << "Welcome in\n";
break;
}
else
cout << "Wrong password: " << user_cin << endl ;
}
else
{
cout << "Account locked\n";
break;
}
}
return 0;
}边栏推荐
- Vulnhub range - darkhole 1
- Google cloud SSH enable root password login
- Uniapp waterfall flow, applet waterfall flow, very simple, suitable for the whole platform
- JS advanced
- Number of wechat applet custom input boxes
- Arduino : No such file or directory
- Apifox simple understanding -- the integrator of web side testing
- What are Baidu collection skills? 2022 Baidu article collection skills
- PHP FPM, workman, spoole, golang simple performance test
- PAT B1056
猜你喜欢
Android Development Notes - Quick Start (from sqllite to room licentiousness) 2

ECS 7-day practical training camp (Advanced route) -- day01 -- setting up FTP service based on ECS

DARKHOLE 2

Wechat applet cloud function does not have dependency option installed

One night I worked as an XPath Terminator: XPath Helper Plus

Panda weekly -2022/02/18

Bloom filter

Divine reversion EA

Print 1 cute every 100 milliseconds ~ with a running lantern effect

Web container basic configuration
随机推荐
Installing or uninstalling VMware could not find the network location
Simple native JS tab bar switching
ECS 7-day practical training camp (Advanced route) -- day01 -- setting up FTP service based on ECS
Jsonp function encapsulation
Bindgetuserinfo will not pop up
wooyun-2014-065513
New features of php7
Android Development Notes - Quick Start (from sqllite to room licentiousness) 2
Database data type design (the most detailed in the whole network)
Solidity get quarterly time
Tcp/ip test questions (III)
Network security detection and prevention test questions (II)
What should I pay attention to in GoogleSEO content station optimization?
Alicloud centos8.0 installing mysql8
5、 Initialization analysis II of hikaricp source code analysis
JS advanced
二、HikariCP获取连接流程源码分析二
Paddleocr learning (II) paddleocr detection model training
Can GoogleSEO only do content without external chain? (e6zzseo)
Est - il sûr d'ouvrir un compte avec de nouvelles dettes? Une faible Commission est - elle crédible?