PAT (Basic Level) Practise (中文)1067. 试密码(20)
来源:互联网 发布:48口网络交换机报价 编辑:程序博客网 时间:2024/05/21 06:46
1067. 试密码(20)
时间限制
400 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
CHEN, Yue
当你试图登录某个系统却忘了密码时,系统一般只会允许你尝试有限多次,当超出允许次数时,账号就会被锁死。本题就请你实现这个小功能。
输入格式:
输入在第一行给出一个密码(长度不超过20的、不包含空格、Tab、回车的非空字符串)和一个正整数N(<= 10),分别是正确的密码和系统允许尝试的次数。随后每行给出一个以回车结束的非空字符串,是用户尝试输入的密码。输入保证至少有一次尝试。当读到一行只有单个#字符时,输入结束,并且这一行不是用户的输入。
输出格式:
对用户的每个输入,如果是正确的密码且尝试次数不超过N,则在一行中输出“Welcome in”,并结束程序;如果是错误的,则在一行中按格式输出“Wrong password: 用户输入的错误密码”;当错误尝试达到N次时,再输出一行“Account locked”,并结束程序。
输入样例1:Correct%pw 3correct%pwCorrect@PWwhatisthepassword!Correct%pw#输出样例1:
Wrong password: correct%pwWrong password: Correct@PWWrong password: whatisthepassword!Account locked输入样例2:
cool@gplt 3coolman@gpltcoollady@gpltcool@gplttry again#输出样例2:
Wrong password: coolman@gpltWrong password: coollady@gpltWelcome in
#include <cstdio>#include <iostream>#include <string>using namespace std;int main(){ string password,temp; int n,cnt=0; cin>>password>>n; getchar(); while(1){ getline(cin,temp); if(temp=="#") break; cnt++; if(cnt<=n&&temp==password){ cout<<"Welcome in"<<endl; break; } else if(cnt<=n&&temp!=password){ cout<<"Wrong password: "<<temp<<endl; if(cnt==n){ cout<<"Account locked"<<endl; break; } } } return 0;}
阅读全文
0 0
- PAT (Basic Level) Practise (中文) 1067. 试密码(20)
- PAT (Basic Level) Practise (中文)1067. 试密码(20)
- PAT (Basic Level) Practise (中文)1067. 试密码(20) 解题报告
- PAT (Basic Level) Practise (中文) 1076. Wifi密码 (15)
- PAT (Basic Level) Practise (中文)
- PAT (Basic Level) Practise (中文)
- PAT (Basic Level) Practise (中文)--1001
- PAT (Basic Level) Practise (中文)
- PAT (Basic Level) Practise (中文)1001
- PAT (Basic Level) Practise (中文)1002
- PAT (Basic Level) Practise (中文) 1007
- PAT (Basic Level) Practise (中文)1004. 成绩排名 (20)
- PAT (Basic Level) Practise (中文)1009. 说反话 (20)
- PAT (Basic Level) Practise (中文)1012. 数字分类 (20)
- PAT (Basic Level) Practise (中文)1013. 数素数 (20)
- PAT (Basic Level) Practise (中文)1019. 数字黑洞 (20)
- PAT (Basic Level) Practise (中文)1027. 打印沙漏(20)
- PAT (Basic Level) Practise (中文)1028. 人口普查(20)
- Python学习笔记——列表
- 结构体的大小与内存对齐规则
- /usr/bin/env: node: No such file or directory
- 使用ST-Link Utility去除STM32芯片读写保护
- jmeter登录压力测试之登录
- PAT (Basic Level) Practise (中文)1067. 试密码(20)
- Python运算符
- LightOJ-1399-线段树求区间相同颜色连续的最大长度
- 分享一波好网站(不定时更新)
- Hibernate(十)多表联查之双向多对多
- MySQL、Oracle分页查询语句
- Python入门<1>爬楼梯
- OKHttp框架
- C语言学习1