문제 링크: https://www.acmicpc.net/problem/2941
백준 문자열 9단계 - 2941번 크로아티아 알파벳를 풀어보았다.
풀이: 크로아티아 알파벳을 다른 문자로 치환하고 개수를 센다.
C++
#include <iostream>
#include <string>
using namespace std;
int main()
{
string croatian[8] = {"c=","c-","dz=","d-","lj","nj","s=","z="};
int idx;
string inp;
cin >> inp;
for(int i = 0; i < 8; i++)
{
while(1)
{
idx = inp.find(croatian[i]);
if(idx == string::npos)
break;
inp.replace(idx,croatian[i].length(),"0");
}
}
cout << inp.length();
}
Python
calpha=["c=","c-","dz=","d-","lj","nj","s=","z="]
inp=input()
for i in calpha:
inp=inp.replace(i,' ')
print(len(inp))
Java
'코테용 문제풀이 > 백준' 카테고리의 다른 글
손익분기점 풀이 (0) | 2023.01.02 |
---|---|
그룹 단어 체커 풀이 (0) | 2023.01.02 |
다이얼 풀이 (0) | 2023.01.02 |
상수 풀이 (0) | 2023.01.02 |
단어의 개수 풀이 (0) | 2023.01.02 |