Problem Solving

[백준/C] 5622

Jintiago 2022. 7. 13. 03:25

또 문제 조건 잘못 보고 뻘짓 한참했다...

 

다이얼에 적힌 알파벳에 따른 시간을 구하는 일반식을 세우고 Z에 대해서만 예외처리를 해 줬는데 계속 틀렸다.

문제를 자세히 보니 중간에 P부터 Q까지 4개가 숫자 하나에 들어있었다..

 

현타 씨게 온다...

그냥 노가다로 다 조건식 세워서 풀었으면 훨씬 빨랐겠다

 

#include <stdio.h>

#define _CRT_SECURE_NO_WARNINGS

int    get_duration(char str[])
{
    int    i;
    int    result;
    
    i = 0;
    result = 0;
    while (str[i] != 0)
    {
        if (str[i] >= 'A' && str[i] <= 'O')
            result = result + (str[i] - 'A') / 3 + 3;
        else if (str[i] >= 'P' && str[i] <= 'S')
            result += 8;
        else if (str[i] >= 'T' && str[i] <= 'V')
            result += 9;
        else if (str[i] >= 'W' && str[i] <= 'Z')
            result += 10;
        i++;
    }
    return (result);
}

int    main(void)
{
    char    str[16];
    
    scanf("%s", str);
    printf("%d\n", get_duration(str));
    return (0);
}