#include<stdio.h>
#include<string.h>
int main(){
int n,i,j,t,c,k,f;
char str[250]="";
scanf("%d",&n);
getchar();
for(i=0;i<n;i++){
gets(str);
t=strlen(str);
if(t<6) {
printf("Your password is tai duan le.\n");
continue;
}
else{
c=0,k=0,f=0;
for(i=0;i<t;i++){
if(str[i]>='0'&&str[i]<='9') {
c=1;
}else if(str[i]>='A'&&str[i]<='Z'||str[i]>='a'&&str[i]<='z'){
k=1;
}else if(str[i]=='.') {
f=1;
}
}
if(f==0) printf("Your password is tai luan le.\n");
else if(c==0) printf("Your password needs zi mu.\n");
else if(k==0) printf("Your password needs shu zi.\n");
else if(c==1&&k==1) printf("Your password is wan mei.\n");
}
}
return 0;
}
第二个循环不要使用i,应该用j:
字母和数字的判断反了,应该这样子:
密码里面没有'.'符号时的提示错了,应该不是提示“太短了”,而应该提示没有'.'符号
#include<stdio.h>
#include<string.h>
int main() {
int n, i, j, t, c, k, f;
char str[250] = "";
scanf("%d", &n);
getchar();
for (i = 0; i < n; i++) {
gets(str);
t = strlen(str);
if (t < 6) {
printf("Your password is tai duan le.\n");
continue;
}
else {
c = 0, k = 0, f = 0;
for (j = 0; j < t; j++) {
if (str[j] >= '0' && str[j] <= '9') {
c = 1;
}
else if (str[j] >= 'A' && str[j] <= 'Z' || str[j] >= 'a' && str[j] <= 'z') {
k = 1;
}
else if (str[j] == '.') {
f = 1;
}
}
if (f == 0) printf("Your password needs dian.\n");
else if (k == 0) printf("Your password needs zi mu.\n");
else if (c == 0) printf("Your password needs shu zi.\n");
else printf("Your password is wan mei.\n");
}
}
return 0;
}
粗略一看,那个t小于6那里应该用break