개발로그필름

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

coding test/백준

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

yuullog 2022. 11. 12. 09:00
728x90
반응형
SMALL

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

 

2941번: 크로아티아 알파벳

예전에는 운영체제에서 크로아티아 알파벳을 입력할 수가 없었다. 따라서, 다음과 같이 크로아티아 알파벳을 변경해서 입력했다. 크로아티아 알파벳 변경 č c= ć c- dž dz= đ d- lj lj nj nj š s= ž z=

www.acmicpc.net

 

코드 풀이
#include <stdio.h>
#include <string.h>

int main(void) {
    char input[100];
    gets(input);
    int cnt = strlen(input);

    // 변경 문자에 =, -, j 가 공통적으로 있기 때문에 경우의 수를 그에 맞춰 나눠준다.
    for (int i = 0; i < strlen(input); i++) {
        if (input[i] == '=') {
            if (input[i - 1] == 'c') 
                cnt--;
            if (input[i - 1] == 's') 
                cnt--;
            if (input[i - 1] == 'z') 
            {
                cnt--;
                if (input[i - 2] == 'd') 
                    cnt--;
            }
        }
        if (input[i] == '-') {
            if (input[i - 1] == 'c') 
                cnt--;
            if (input[i - 1] == 'd') 
                cnt--;
        }
        if (input[i] == 'j') 
        {
            if (input[i - 1] == 'l') 
                cnt--;
            if (input[i - 1] == 'n') 
                cnt--;
        }
    }
    printf("%d\n", cnt);
}
	

 
 

 

반응형
LIST

'coding test > 백준' 카테고리의 다른 글

[백준] C | 1152 | 단어의 개수  (0) 2022.11.14
[백준] C | 1316 | 그룹 단어 체커  (0) 2022.11.13
[백준] C 2292 벌집  (0) 2022.11.11
[백준] C 1193 분수 찾기  (0) 2022.11.10
[백준] javascript 10430 나머지  (0) 2022.08.17