[ 백준 ] 2941번 크로아티아 알파벳
문제
https://www.acmicpc.net/problem/2941
풀이
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>
#include<vector>
#include<string>
using namespace std;
int main()
{
vector<string> Alpabet = { "c=","c-" ,"dz=" ,"d-" ,"lj" ,"nj" ,"s=" ,"z=" };
string str;
cin >> str;
int result = 0;
int findCount = 0;
int limit = 3;
for (int i = 0; i < str.size(); i++) {
bool isThreeFind = false;
bool isIndexOver = false;
int endIndex = 0;
string threeStr = "";
string twoStr = "";
//3개 찾기
for (int c = 0; c < 3; c++) {
int curIndex = i + c;
if (curIndex > str.size() - 1) {
isIndexOver = true;
break;
}
threeStr.push_back(str[curIndex]);
endIndex = curIndex;
}
if (!isIndexOver) {
for (int j = 0; j < Alpabet.size(); j++) {
if (threeStr == Alpabet[j]) {
i = endIndex;
isThreeFind = true;
result += 3;
findCount++;
break;
}
}
}
if (!isThreeFind) {
isIndexOver = false;
endIndex = 0;
limit = 2;
//2개 찾기
for (int c = 0; c < 2; c++) {
int curIndex = i + c;
if (curIndex > str.size() - 1) {
isIndexOver = true;
break;
}
twoStr.push_back(str[i + c]);
endIndex = i + c;
}
for (int j = 0; j < Alpabet.size(); j++) {
if (twoStr == Alpabet[j]) {
i = endIndex;
result += 2;
findCount++;
break;
}
}
}
}
cout << str.size() - result + findCount;
}
이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.