백준 - 15829 Hashing - Swift

AekT·2021년 11월 13일
0
post-thumbnail

백준 15829 Hashing

문제 : https://www.acmicpc.net/problem/15829

Code :

let mod = 1234567891
readLine()
let input = Array(readLine()!).map{Int(exactly: $0.asciiValue!)! - 96}
var hash = 0
var m = 1
for i in input{
    hash = (hash + i*m) % mod
    m = (m*31) % mod
}
print(hash)
profile
으악

0개의 댓글