본문 바로가기
코테/백준

[백준] 1316 그룹단어체커 스위프트

by 리드맥 2021. 12. 29.

코드:

let input = Int(readLine()!)!
var count = 0
for i in 1...input {
    var input1 = readLine()!
    var arr:[Character] = []
    for j in input1 {
        if !arr.contains(j) {
            arr.append(j)
        }else if arr.last != j {
            break
        }else {
            arr.append(j)
        }
        if input1.count == arr.count {
            count += 1
        }
    }

}
print(count)


설명:
연속된 수 last와 겹치면 그룹 단어로 넘어가고  last에 없는데 j 를 포함 하고 있으면 같은단어가 떨어져 있는거기 때문에 그룹 단어가 아니다


결과:

댓글