Notice
Recent Posts
Recent Comments
Link
«   2026/05   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
Archives
Today
Total
관리 메뉴

mo1lusca의 블로그

[백준] 2941 크로아티아 알파벳 - C 본문

PS

[백준] 2941 크로아티아 알파벳 - C

mo1lusca 2025. 4. 12. 20:29

 

https://www.acmicpc.net/problem/2941

 

 


 

 

문제에서 주어진 크로아티아 알파벳들을 하나의 묶음으로 생각해야 하는 문제다.

 

#include <stdio.h>
#include <string.h>

int croatian(char s[], int i);

int main() {
    char s[102];
    scanf("%s", s);
    int len = strlen(s);

    int cnt = 0;
    for (int i = 0; i < len; i++) {
        i += croatian(s, i);
        cnt++;
    }
    printf("%d", cnt);
    return 0;
}

int croatian(char s[], int i) {
    if (s[i] == 'c' && s[i + 1] == '=') {
        return 1;
    }
    else if (s[i] == 'c' && s[i + 1] == '-') {
        return 1;
    }
    else if (s[i] == 'd' && s[i + 1] == 'z' && s[i + 2] == '=') {
        return 2;
    }
    else if (s[i] == 'd' && s[i + 1] == '-') {
        return 1;
    }
    else if (s[i] == 'l' && s[i + 1] == 'j') {
        return 1;
    }
    else if (s[i] == 'n' && s[i + 1] == 'j') {
        return 1;
    }
    else if (s[i] == 's' && s[i + 1] == '=') {
        return 1;
    }
    else if (s[i] == 'z' && s[i + 1] == '=') {
        return 1;
    }
    else {
        return 0;
    }
}

 

 

크로아티아 알파벳이라면 for문에서 해당 글자수만큼 검사를 피하기 위해

croatian함수의 return값만큼 for문의 i값을 변경해주었다.