2941번: 크로아티아 알파벳

메모리

시간

2020 KB

0 ms

문제 풀이

크로아티아 알파벳을 변경해서 입력을 하면 해당 입력값이 총 몇개의 크로아티아 알파벳으로 이루어져있는지 출력하는 문제이다.

해당 표를 보면 3개의 문자로 만들수 있는 크로아티아 알파벳 제외하고 모두 크로아티아 알파벳은 2개의 문자로 만들 수 있다.

표에 나와있지 않은 알파벳은 하나로 카운트를 해주면 된다.

경우의 수의 조건에 맞다면 카운트를 올리고 2개의 문자열이 사용되었으니 해당 인덱스를 하나씩 당겨준다.


Code

#include <iostream>

using namespace std;
int check_val(string str, int i)
{
	if ((str[i] == 'c' && (str[i+1] == '=' || str[i+1] == '-'))
	|| (str[i] == 'd' && str[i + 1] == '-')
	|| (str[i] == 'l' && str[i + 1] == 'j')
	|| (str[i] == 'n' && str[i + 1] == 'j')
	|| (str[i] == 's' && str[i + 1] == '=')
	|| (str[i] == 'z' && str[i + 1] == '=')
	)
	return (1);
	return(0);
}

int main()
{
	string str;
	cin >> str;
	int len = str.length();
	int result = 0;
	for (int i = 0; i < len; i++)
	{
		if (check_val(str, i))
		{
			result++;
			i++;
		}
		else if (str[i] == 'd' && str[i + 1] == 'z' && str[i + 2] == '=')
		{
			result++;
			i += 2;
		}
		else
			result++;
	}
	cout << result << '\\n'; 
	return 0;
}