/* 문제 */
// 예전에는 운영체제에서 크로아티아 알파벳을 입력할 수가 없었다. 따라서, 다음과 같이 크로아티아 알파벳을 변경해서 입력했다.
// 예를 들어, ljes=njak은 크로아티아 알파벳 6개(lj, e, š, nj, a, k)로 이루어져 있다.
// 단어가 주어졌을 때, 몇 개의 크로아티아 알파벳으로 이루어져 있는지 출력한다.
// dž는 무조건 하나의 알파벳으로 쓰이고, d와 ž가 분리된 것으로 보지 않는다. lj와 nj도 마찬가지이다. 위 목록에 없는 알파벳은 한 글자씩 센다.
/*
č -> c=
ć -> c-
dž -> dz=
đ -> d-
lj -> lj
nj -> nj
š -> s=
ž -> z=
*/
/* 입력 */
// 첫째 줄에 최대 100글자의 단어가 주어진다. 알파벳 소문자와 '-', '='로만 이루어져 있다.
// 단어는 크로아티아 알파벳으로 이루어져 있다. 문제 설명의 표에 나와있는 알파벳은 변경된 형태로 입력된다.
/* 출력 */
// 입력으로 주어진 단어가 몇 개의 크로아티아 알파벳으로 이루어져 있는지 출력한다.
/* 예제 */
// ljes=njak -> 6
// ddz=z= -> 3
// nljj -> 3
import Foundation
func quiz2941() {
let input: String = readLine()!
let croatiaLetter = ["c=", "c-", "dz=", "d-", "lj", "nj", "s=", "z="]
var letters: Int = input.count
var index = 0
while index < input.count - 1 {
let startIndex = input.index(input.startIndex, offsetBy: index)
let endIndex = input.index(input.startIndex, offsetBy: index)
var lookupString: String = String(input[startIndex...endIndex])
if index < input.count - 2 {
let end3Index = input.index(input.startIndex, offsetBy: index + 2)
lookupString = String(input[startIndex...end3Index])
print("\(index)~\(index + 2)th: \(lookupString)")
if croatiaLetter.contains(lookupString) {
letters -= 2
index += 2
}
}
if index < input.count - 1 {
let end2Index = input.index(input.startIndex, offsetBy: index + 1)
lookupString = String(input[startIndex...end2Index])
print("\(index)~\(index + 1)th: \(lookupString)")
if croatiaLetter.contains(lookupString) {
letters -= 1
index += 1
}
}
index += 1
// print(index)
}
print(letters)
}
quiz2941()
Swift
복사