#include <stdio.h>
#include <string.h>
#define DEFALUT_LEN 11
// caps 잠금인지 확인하는 함수
int is_caps_lock_f(char *pwd, char *my_pwd, int len){
char cmp_pwd[DEFALUT_LEN] = {0};
int count = 0;
// 소문자 -> 대문자
// 대문자 -> 소문자
// 숫자는 그대로
// 비교할 비번 배열에 바꿔줌
for(int i = 0; i < len; i++){
if(pwd[i] >= 'a' && pwd[i] <= 'z'){
cmp_pwd[i] = pwd[i] - 32;
count++;
}
else if(pwd[i] >= 'A' && pwd[i] <= 'Z'){
cmp_pwd[i] = pwd[i] + 32;
count++;
}
else{
cmp_pwd[i] = pwd[i];
count++;
}
}
// 비교 비번이랑 내 비번이 모두 일치할 경우
if(is_exact(cmp_pwd, my_pwd, count)){
return 1;
}
return 0;
}
// 숫자키 잠금인지 확인하는 함수
int is_num_lock_f(char *pwd, char *my_pwd, int len, int len_my){
char cmp_pwd[DEFALUT_LEN] = {0};
int count = 0;
// 비교할 비번 배열에 숫자를 제외하고 알파벳만 넣음
for(int i = 0; i < len; i++){
if((pwd[i] >= 'a' && pwd[i] <= 'z')||
(pwd[i] >= 'A' && pwd[i] <= 'Z')){
cmp_pwd[count] = pwd[i];
count++;
}
}
// 만약 비교 비번이랑 내 비번이랑 길이 다르면 return 0(num_lock 아님)
if(count != len_my){
return 0;
}
// 만약 비교 비번이랑 내 비번이랑 길이 같으면
else{
// 비교 비번이랑 내 비번이 모두 일치할 경우
if(is_exact(cmp_pwd, my_pwd, count)){
return 1;
}
// 비교 비번이랑 내 비번의 모든 알파벳이 대소문자가 모두 반대로일 경우
else if(is_caps_lock_f(cmp_pwd, my_pwd, count)){
return 2;
}
// 해당 사항 없을 경우
return 0;
}
}
// 모든 비번 일치하는지 비교하는 함수
int is_exact(char *pwd, char *my_pwd, int len){
int count = 0;
for(int i = 0; i < len; i++){
if(pwd[i] == my_pwd[i]){
count ++;
}
}
if(count == len){
return 1;
}
else{
return 0;
}
}
int main(void){
// 테스트 케이스 입력
int num = 0;
scanf("%d", &num);
for(int i = 0; i < num; i++){
getchar();
// 원래 비번과 내가 친 비번 입력
char pwd[DEFALUT_LEN] = {0}, my_pwd[DEFALUT_LEN] = {10};
scanf("%s %s", pwd, my_pwd);
int len = strlen(pwd);
int len_my = strlen(my_pwd);
// 원래 비번길이와 내 비번길이가 다를 경우
if(len != len_my){
// 숫자키 잠금인지 검사한다.
int is_num_lock = is_num_lock_f(pwd, my_pwd, len, len_my);
// 숫자키만 잠금일 경우(숫자를 제외한 모든 알파벳 맞음)
if(is_num_lock == 1){
printf("Case %d: Wrong password. Please, check your num lock key.\n", i+1);
}
// 숫자키 및 caps 잠금일 경우
// (숫자를 제외한 모든 알파벳이 대소문자가 모두 반대로일 경우)
else if(is_num_lock == 2){
printf("Case %d: Wrong password. Please, check your caps lock and num lock keys.\n", i+1);
}
// 전부 틀린 비번일 경우
else{
printf("Case %d: Wrong password.\n", i+1);
continue;
}
}
// 원래 비번길이와 내 비번길이가 같을 경우
else{
// 모든 비번이 일치 할 경우 (성공)
if(is_exact(pwd, my_pwd, len)){
printf("Case %d: Login successful.\n", i+1);
}
// 모든 비번이 불일치 할 경우
else{
// caps 잠금으로 숫자는 맞지만 대소문자가 모두 반대로일 경우
if(is_caps_lock_f(pwd, my_pwd, len)){
printf("Case %d: Wrong password. Please, check your caps lock key.\n", i+1);
}
// 전부 틀린 비번일 경우
else{
printf("Case %d: Wrong password.\n", i+1);
}
}
}
}
return 0;
}