백준 2941 크로아티아 알파벳 / C++

이유참치·2025년 12월 15일

백준

목록 보기
97/249

문제 : 2941

풀이 point

크로아티아 알파벳을 발견하면 그 알파벳을 특정 문자로 변경한다.

풀이 방법

크로아티아 알파벳을 저장하여 문자열과 비교한다.
비교해서 크로아티아 알파벳과 일치할 경우 그 알파벳을 특정 문자로 변경한다.
문자열의 길이를 출력한다.

코드

//백준 2941, 크로아티아 알파벳

#include <iostream>

int main(){
    std::string alpha[8] = {"c=", "c-", "dz=", "d-", "lj", "nj", "s=", "z="};
    std::string s;
    std::cin >> s;

    for(int i{0}; i<8; ++i){
        while(true){
            int idx = s.find(alpha[i]);
            if(idx == std::string::npos) break;
            s.replace(idx, alpha[i].size(), "#");
        }
    }

    std::cout << s.size();

    return 0;
}
profile
임아리 - 대학생

0개의 댓글