๐Ÿ—๏ธ Algorithm/๐ŸŸฆ ์ด๊ฒƒ์ด ์ทจ์—…์„ ์œ„ํ•œ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ

[์ด๊ฒƒ์ด ์ทจ์—…์„ ์œ„ํ•œ ์ฝ”๋”ฉ ํ…Œ์ŠคํŠธ] [๊ตฌํ˜„] [Python] ๋Ÿญํ‚ค ์ŠคํŠธ๋ ˆ์ดํŠธ

Dbswnstjd 2022. 4. 22. 01:22

๋ฌธ์ œ

https://www.acmicpc.net/problem/18406

 

18406๋ฒˆ: ๋Ÿญํ‚ค ์ŠคํŠธ๋ ˆ์ดํŠธ

์ฒซ์งธ ์ค„์— ์ ์ˆ˜ N์ด ์ •์ˆ˜๋กœ ์ฃผ์–ด์ง„๋‹ค. (10 ≤ N ≤ 99,999,999) ๋‹จ, ์ ์ˆ˜ N์˜ ์ž๋ฆฟ์ˆ˜๋Š” ํ•ญ์ƒ ์ง์ˆ˜ ํ˜•ํƒœ๋กœ๋งŒ ์ฃผ์–ด์ง„๋‹ค.

www.acmicpc.net

ํ’€์ด

# ๊ตฌํ˜„ - ๋Ÿญํ‚ค ์ŠคํŠธ๋ ˆ์ดํŠธ
n = int(input())
length = len(n)
summary = 0

# ์™ผ์ชฝ ๋ถ€๋ถ„์˜ ์ž๋ฆฟ์ˆ˜ ํ•ฉ ๋”ํ•˜๊ธฐ
for i in range(length//2):
    summary += int(n[i])

# ์˜ค๋ฅธ์ชฝ ๋ถ€๋ถ„์˜ ์ž๋ฆฟ์ˆ˜ ํ•ฉ ๋นผ๊ธฐ
for i in range(length//2, length):
    summary -= int(n[i])

    # ์™ผ์ชฝ ๋ถ€๋ถ„๊ณผ ์˜ค๋ฅธ์ชฝ ๋ถ€๋ถ„์˜ ์ž๋ฆฟ์ˆ˜ ํ•ฉ์ด ๋™์ผํ•œ์ง€ ๊ฒ€์‚ฌ
if summary == 0:
    print("LUCKY")
else:
    print("READY")