Algorithm/BOJ
[c++][BOJ][2941] 크로아티아 알파벳
kim-hasa
2021. 10. 28. 18:54
https://www.acmicpc.net/problem/2941
2941번: 크로아티아 알파벳
예전에는 운영체제에서 크로아티아 알파벳을 입력할 수가 없었다. 따라서, 다음과 같이 크로아티아 알파벳을 변경해서 입력했다. 크로아티아 알파벳 변경 č c= ć c- dž dz= đ d- lj lj nj nj š s= ž z=
www.acmicpc.net
표현할 수 없는 크로아티아 알파벳을 변환해서 구하는 문제입니다.
처음부터 index로 위치를 찾고, 하나하나 경우의 수를 찾아가면서 구하는 문제입니다.
#include <iostream>
#include <string>
using namespace std;
int main(){
string str;
cin >> str;
int index = 0;
int count = 0;
int len = str.length();
while(index < len)
{
if(str[index] == 'c')
{
if(str[index+1] == '=')
{
count++;
index += 2;
}
else if(str[index+1] == '-')
{
count++;
index += 2;
}
else
{
count++;
index++;
}
}
else if(str[index] == 'd')
{
if(str[index+1] == '-')
{
count++;
index += 2;
}
else if(str[index+1] == 'z' && str[index+2] == '=')
{
count++;
index += 3;
}
else
{
count++;
index++;
}
}
else if(str[index] == 'l')
{
if(str[index+1] == 'j')
{
count++;
index += 2;
}
else
{
count++;
index++;
}
}
else if(str[index] == 'n')
{
if(str[index+1] == 'j')
{
count++;
index += 2;
}
else
{
count++;
index++;
}
}
else if(str[index] == 's')
{
if(str[index+1] == '=')
{
count++;
index += 2;
}
else
{
count++;
index++;
}
}
else if(str[index] == 'z')
{
if(str[index+1] == '=')
{
count++;
index += 2;
}
else
{
count++;
index++;
}
}
else
{
count++;
index++;
}
}
cout << count;
}