本题要求你帮助某网站的用户注册模块写一个密码合法性检查的小功能。该网站要求用户设置的密码必须由不少于6个字符组成,并且只能有英文字母、数字和小数点
.
,还必须既有字母也有数字。标签:dig out 解决 etc for -- ann tar 设置
.
,还必须既有字母也有数字。输入第一行给出一个正整数 N(≤ 100),随后 N 行,每行给出一个用户设置的密码,为不超过 80 个字符的非空字符串,以回车结束。
对每个用户的密码,在一行中输出系统反馈信息,分以下5种:
Your password is wan mei.
;Your password is tai duan le.
;Your password is tai luan le.
;Your password needs shu zi.
;Your password needs zi mu.
。5
123s
zheshi.wodepw
1234.5678
WanMei23333
pass*word.6
Your password is tai duan le.
Your password needs shu zi.
Your password needs zi mu.
Your password is wan mei.
Your password is tai luan le.
1 #include <stdio.h> 2 #include <string.h> 3 #include <ctype.h> 4 5 int main(){ 6 int n,luanma=0,shuzi,zimu,dian; 7 char pwd[99]; 8 scanf("%d",&n); 9 getchar(); 10 for(int i=0;i<n;i++){ 11 //scanf("%s",&pwd); 12 //为解决密码中混入空格的问题,用gets代替scanf,用getchar消掉上一个回车 13 gets(pwd); 14 if(strlen(pwd)<6){ 15 printf("Your password is tai duan le.\n"); 16 }else { 17 shuzi=0;zimu=0; luanma=0;dian=0; 18 for(int j=0;j<strlen(pwd);j++){ 19 if(pwd[j]==‘.‘){ 20 dian++; 21 }else if(isalpha(pwd[j])) 22 zimu++; 23 else if(isdigit(pwd[j])) 24 shuzi++; 25 else{ 26 luanma++; 27 } 28 } 29 if(luanma){ 30 printf("Your password is tai luan le.\n"); 31 } 32 else if(zimu==0) 33 printf("Your password needs zi mu.\n"); 34 else if(shuzi==0) 35 printf("Your password needs shu zi.\n"); 36 else{ 37 printf("Your password is wan mei.\n"); 38 } 39 } 40 } 41 42 return 0; 43 }
标签:dig out 解决 etc for -- ann tar 设置
原文地址:https://www.cnblogs.com/geyang/p/12290458.html