Problem Solving

[백준/C] 2941

Jintiago 2022. 7. 15. 01:51

조건을 잘못 봐서 또 뻘짓해버렸다...

 

크로아티아문자의 개수를 세는 문제다.

 

-, = 등 특수문자와 특정 알파벳이 혼합된 형태의 문자는 하나로 보는데,

따라서 특수문자와 알파벳 하나가 결합된 형태는 전체 문자열에서 알파벳 수 세는 것으로 해결 된다.

알파벳 두 개가 연속으로 쓰이는 크로아티아문자가 나올 때 마다 갯수를 하나씩 감소시켰다.

 

#include <stdio.h>

int    alpha_len(char str[])
{
    int    i;
    int    len;

    i = 0;
    len = 0;
    while (str[i] != '\0')
    {
        if (str[i] >= 'a' && str[i] <= 'z')
            len++;
        i++;
    }
    return (len);
}

int    get_kro_num(char str[])
{
    int    cnt;
    int    i;

    i = 0;
    cnt = alpha_len(str);
    while (str[i] != '\0')
    {
        if ((str[i] == 'l' || str[i] == 'n') && str[i + 1] == 'j')
            cnt--;
        else if (str[i] == 'd' && str[i + 1] == 'z' && str[i + 2] == '=')
            cnt--;
        i++;
    }
    return (cnt);
}

int    main(void)
{
    char    str[101];

    scanf("%s", str);
    printf("%d\n", get_kro_num(str));
}