백준 2941번 크로아티아 알파벳(C언어)

최정우·2022년 7월 4일
0

백준 문제풀이

목록 보기
16/26


Code

#include <stdio.h>

int main()
{
	char alpha[101] = {};
	int i, cnt = 0;

	scanf_s("%s", alpha, sizeof(alpha));
	for (i = 0; alpha[i] != '\0'; i++)
	{
		if (alpha[i] == 'c' && alpha[i + 1] == '=')
		{
			cnt++;
			i++;
		}
		else if (alpha[i] == 'c' && alpha[i + 1] == '-')
		{
			cnt++;
			i++;
		}
		else if (alpha[i] == 'd' && alpha[i + 1] == 'z' && alpha[i + 2] == '=')
		{
			cnt++;
			i++;
			i++;
		}
		else if (alpha[i] == 'd' && alpha[i + 1] == '-')
		{
			cnt++;
			i++;
		}
		else if (alpha[i] == 'l' && alpha[i + 1] == 'j')
		{
			cnt++;
			i++;
		}
		else if (alpha[i] == 'n' && alpha[i + 1] == 'j')
		{
			cnt++;
			i++;
		}
		else if (alpha[i] == 's' && alpha[i + 1] == '=')
		{
			cnt++;
			i++;
		}
		else if (alpha[i] == 'z' && alpha[i + 1] == '=')
		{
			cnt++;
			i++;
		}
		else
		{
			cnt++;
		}
	}
	printf("%d", cnt);

	return 0;
}

Key Point

  1. 문자열로 알파벳을 입력받고 크로아티아 알파벳에 해당하는 알파벳이 나올때 2문자면 카운팅을 1번 생략, 3문자면 2번 생략
profile
WHEN LIFE GIVES YOU LEMONS, MAKE LEMONADE

0개의 댓글