提交记录 #149
提交时间:2024-11-10 13:03:03
语言:c
状态:Unaccepted
编译情况:编译成功
固定测试点#1:
固定测试点#2:
附加测试点暂不可用
36【应用】安全的密码
#include <stdio.h>
#include <string.h>
#include <ctype.h>
const char* check_password_safety(const char *password) {
int length = strlen(password);
if (length < 6) {
return "Not Safe";
}
int has_digit = 0;
int has_lower = 0;
int has_upper = 0;
int has_special = 0;
for (int i = 0; i < length; ++i) {
if (isdigit(password[i])) {
has_digit = 1;
} else if (islower(password[i])) {
has_lower = 1;
} else if (isupper(password[i])) {
has_upper = 1;
} else {
has_special = 1;
}
}
int types_count = has_digit + has_lower + has_upper + has_special;
if (types_count == 1) {
return "Not Safe";
} else if (types_count == 2) {
return "Medium Safe";
} else {
return "Safe";
}
}
int main() {
int N;
scanf("%d", &N);
getchar(); // 清除换行符
for (int i = 0; i < N; i++) {
char password[21]; // 最多20个字符 + 1个结束符
fgets(password, sizeof(password), stdin);
// 去除换行符
password[strcspn(password, "\n")] = 0;
const char* safety = check_password_safety(password);
printf("%s\n", safety);
}
return 0;
}