我是靠谱客的博主 重要水蜜桃,这篇文章主要介绍PAT乙级 1067 试密码 (20 分) C语言,现在分享给大家,希望可以做个参考。

一、题目

在这里插入图片描述

二、源代码

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//注意只有第一个正确密码是明确不含空格的,其余的可能就含有空格了... #include<stdio.h> #include<string.h> int cmp(char s[],char t[]) { if(strlen(s)!=strlen(t)-1)return 1; else { for(int i=0;i<strlen(t)-1;i++) { if(s[i]!=t[i]) return 1; } return 0; } } int main() { int n,count=0; char s[21],t[100]; scanf("%s %d",s,&n); getchar(); while(1) { fgets(t,100,stdin); //printf("s=%s,t=%s ",s,t); if(cmp("#",t)==0)break; if(cmp(s,t)==0 && count<n) { printf("Welcome in"); break; } else { if(count<n) { printf("Wrong password: %s",t); count++; if(count==n) { printf("Account locked"); break; } } } } return 0; }

三、运行结果

在这里插入图片描述

最后

以上就是重要水蜜桃最近收集整理的关于PAT乙级 1067 试密码 (20 分) C语言的全部内容,更多相关PAT乙级内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(71)

评论列表共有 0 条评论

立即
投稿
返回
顶部