Recent Posts
Notice
No Rules Rules
크로아티아 알파벳 (feat. 백준, 2941번) 본문
728x90
반응형
크로아티아 알파벳
https://www.acmicpc.net/problem/2941
2941번: 크로아티아 알파벳
예전에는 운영체제에서 크로아티아 알파벳을 입력할 수가 없었다. 따라서, 다음과 같이 크로아티아 알파벳을 변경해서 입력했다. 크로아티아 알파벳 변경 č c= ć c- dž dz= đ d- lj lj nj nj š s= ž z=
www.acmicpc.net
반응형
// woohyeon.kim
// kim519620.tistory.com
#include <iostream>
#include <set>
#include <cstring>
using namespace std;
int main() {
ios::sync_with_stdio(false), cin.tie(NULL);
register int ans = 0, pos;
string str;
set<string> tmp;
tmp.insert("c="), tmp.insert("c-"), tmp.insert("dz="), tmp.insert("d-"), tmp.insert("lj"), tmp.insert("nj"), tmp.insert("s="), tmp.insert("z=");
cin >> str;
for (auto iter = tmp.begin(); iter != tmp.end();) {
pos = str.find(iter->c_str());
if (pos >= 0)
str.replace(pos, iter->size(), "1"), ++ans;
else
++iter;
}
cout << ans + (str.size() - ans);
return 0;
}
// *&)*@*
- 문제로 주어진 문자열을 미리 갖고 있습니다. 이것을 사전 이라고 하겠습니다.
- 입력된 문자열 중 사전에 있는 문자열이 있다면 해당 문자열을 "1" 로 변경하고 카운팅을 합니다. (++ans)
- 2번 조건에서 문자열이 있다면, 해당 문자열로 다시 검사합니다. 이 과정은 찾지 못할때까지 입니다.
- 3번 과정이 끝나면 다음 사전의 문자열에 대해서 2번부터 반복합니다.
- 입력된 문자열 중 "1"로 변경된 문자열의 개수는 카운팅 개수(ans)와 같습니다.
- 따라서 ans + (입력된 문자열의 길이 - ans) 이 답이 되게 됩니다.
728x90
반응형
'생활 > 코테' 카테고리의 다른 글
주유소 (feat. 백준, 13305번) (0) | 2022.08.11 |
---|---|
그룹 단어 체커 (feat. 백준, 1316번) (0) | 2022.08.11 |
다이얼 (feat. 백준, 5622번) (0) | 2022.08.11 |
상수 (feat. 백준, 2908번) (0) | 2022.08.11 |
단어의 개수 (feat. 백준, 1152번) (0) | 2022.08.11 |
Comments