티스토리 뷰

Algorithm/BOJ

백준 2941번 C++

poopooreum 2023. 8. 15. 08:05
반응형
백준 2941번 크로아티아 알파벳

https://www.acmicpc.net/problem/2941

2941번: 크로아티아 알파벳

예전에는 운영체제에서 크로아티아 알파벳을 입력할 수가 없었다. 따라서, 다음과 같이 크로아티아 알파벳을 변경해서 입력했다. 크로아티아 알파벳 변경 č c= ć c- dž dz= đ d- lj lj nj nj š s= ž z=

www.acmicpc.net



정답 코드

#include<iostream>
#include<string>
using namespace std;
string str;
string map[8] = { "c=","c-","dz=",
"d-","lj","nj","s=","z="
};
int find(int k);
int main() {
	cin >> str;
	int cnt = 0;
	int len2 = str.length();
	for (int x = 0; x < 8; x++) {
		int len = find(x);
		cnt += len;
	}
	
	cout << len2-cnt;
}
int find(int k) {
	int a = 0, b = 0, cnt = 0;
	while (1) {
		int res = str.find(map[k], b);
		if (res == -1)
			break;
			cnt++;
			b = res + 1;
	}
	return cnt;
}

문제 풀이

string의 find함수를 이용해서 풀었습니다.

반응형

'Algorithm > BOJ' 카테고리의 다른 글

백준 3003번 C++  (0) 2023.08.15
백준 2960번 C++  (0) 2023.08.15
백준 2920번 C++  (0) 2023.08.15
백준 2908번 C++  (0) 2023.08.14
백준 2903번 C++  (0) 2023.08.14
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
글 보관함