n = int(input())
word = input()
result = 0
alpha = {
'a':1,
'b':2,
'c':3,
'd':4,
'e':5,
'f':6,
'g':7,
'h':8,
'i':9,
'j':10,
'k':11,
'l':12,
'm':13,
'n':14,
'o':15,
'p':16,
'q':17,
'r':18,
's':19,
't':20,
'u':21,
'v':22,
'w':23,
'x':24,
'y':25,
'z':26,
}
for i in range(len(word)):
result += alpha[word[i]] * (31**i)
print(result % 1234567891)
๋ฌธ์ ํ์ด
1. ๊ฐ ์ํ๋ฒณ ๊ฐ์ ์ง์ ํ๋ค. => ์์คํค์ฝ๋๋ฅผ ์ฌ์ฉํด๋ ๋์ง๋ง ํ๋ฒ ์ด๋ ๊ฒ ํด๋ณด๊ณ ์ถ์๋ค.
2. ์ฃผ์ด์ง ์์ for๋ฌธ์ ์ด์ฉํด ๊ตฌํ
3. result๊ฐ์ 1234567891๋ก ๋๋ ๋๋จธ์ง ๊ฐ ์ถ๋ ฅ
'๐ฏ CodingTest > BaekJoon' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[BaekJoon] 1003 ํผ๋ณด๋์น ํจ์ (0) | 2022.04.12 |
---|---|
[BaekJoon] 18111 ๋ง์ธํฌ๋ํํธ (0) | 2022.04.11 |
[BaekJoon] 2805 ๋๋ฌด์๋ฅด๊ธฐ (0) | 2022.04.11 |
[BaekJoon] 1654 ๋์ ์๋ฅด๊ธฐ (0) | 2022.04.11 |
[BaekJoon] 10845 ํ (0) | 2022.04.11 |