MapleStory Finger Point

๐Ÿƒ‍โ™‚๏ธBaekjoon/Python

#2745 ์ง„๋ฒ• ๋ณ€ํ™˜ - python

HYEJU01 2024. 4. 27. 20:02
N, B = input().split()
result = 0
N= N[::-1]
ary = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"

for i in range (len(N)) :
    result += (int(B) ** i) * (ary.index(N[i])) 

print(result)

 

๐Ÿ’ก  B์ง„๋ฒ• ์ˆ˜  N ์„ 10์ง„์ˆ˜๋กœ ๋ณ€ํ™˜ํ•˜๋Š” ๋ฐฉ๋ฒ•

๊ฐ ์ž๋ฆฌ๊ฐ’๊ณผ ๊ฐ€์ค‘์น˜๊ฐ’์„ ๊ณฑํ•ด์„œ b^0 b^1 b^2 ๋”ํ•œ๋‹ค

 

 

 

๐Ÿ’ก ์ง„๋ฒ• ๋ณ€ํ™˜ ์ƒ์„ธ์„ค๋ช… !!

0)  10์ง„์ˆ˜๋Š” 0~9 ๋ฅผ ์‚ฌ์šฉํ•˜์ง€๋งŒ , 16์ง„์ˆ˜๋Š” 0~ F ๊นŒ์ง€ , 36์ง„์ˆ˜๋Š” 0~Z ๊นŒ์ง€์‚ฌ์šฉํ•˜๋ฏ€๋กœ arr ๋ฅผ ํ†ตํ•ด์„œ 0~Z๋ฅผ ๋ฏธ๋ฆฌ ์ง€์ •ํ•ด์ค€๋‹ค.

1) ๊ฐ ์ž๋ฆฌ๊ฐ’์„ ์•Œ๊ธฐ ์œ„ํ•ด์„œ len (N) ์„ ํ†ตํ•ด์„œ ๊ธธ์ด๋ฅผ ์•Œ์•„๋‚ธ๋‹ค. 

2) ๊ฐ ์ž๋ฆฌ ๊ฐ’ * ๊ฐ€์ค‘์น˜ ๊ฐ’  =>  N[์ž๋ฆฌ๊ฐ’] * B^0 ~  =>  N[i]  * int(B) ** i  

(+) ๊ฐ ์ž๋ฆฌ๊ฐ’์— ๊ฐ€์ค‘์น˜ ๊ฐ’์ด  ex) Z^4 Z^3 Z^2 Z^1 Z^0  ๋ฐ˜๋Œ€๋กœ ๊ณฑํ•ด์ ธ์•ผ๋˜๋Š”๋ฐ,  => [::-1] ๋ฅผ ํ†ตํ•ด ๊ฑฐ๊พธ๋กœ ์ถœ๋ ฅํ•ด์คฌ์œผ๋ฏ€๋กœ ๊ดœ์ฐฎ๋‹ค.

3) ๋”ํ•œ๋‹ค =>  result += 

 

๐Ÿ’ฌ  ๋ฆฌ์ŠคํŠธ.index(i)  ๋ฆฌ์ŠคํŠธ ์•ˆ์˜ i ๋ผ๋Š” ๊ฐ’์˜ ์ธ๋ฑ์Šค๋ฅผ ๋ฐ›์•„์˜จ๋‹ค.

๐Ÿ’ฌ len(N) N ๊ธธ์ด๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.