๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm/๋ฐฑ์ค€(BOJ)

[ ํŒŒ์ด์ฌ(python) ] ๋ฐฑ์ค€ 1436 - ์˜ํ™”๊ฐ๋… ์ˆŒ

by YWTechIT 2021. 5. 22.
728x90

๐Ÿ“ ๋ฐฑ์ค€ 1436 - ์˜ํ™”๊ฐ๋… ์ˆŒ

๋ฐฑ์ค€ 1436 - ์˜ํ™”๊ฐ๋… ์ˆŒ


โšก๏ธ ๋‚˜์˜ ํ’€์ด

์ „ํ˜•์ ์ธ ๋ธŒ๋ฃจํŠธํฌ์Šค๋ฌธ์ œ๋‹ค.

 

  1. 6์ด ์ ์–ด๋„ 3๊ฐœ ์ด์ƒ ๋“ฑ์žฅํ•ด์•ผ ํ•œ๋‹ค.
  2. number+=1์”ฉ ์ฆ๊ฐ€ํ•˜๋ฉด์„œ 666์ด ์žˆ๋Š”์ง€ ํ™•์ธํ•œ๋‹ค.
  3. number๊ฐ€ ์žˆ์œผ๋ฉด, result์— ์ถ”๊ฐ€์‹œํ‚จ๋‹ค.

 

์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๊ณ  ๋‚˜๋‹ˆ๊นŒ ๊ตณ์ด result์— ์ถ”๊ฐ€์‹œํ‚ค์ง€ ์•Š์•„๋„ ๋œ๋‹ค๋Š” ์ƒ๊ฐ์„ ํ–ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  while๋ฌธ ์ข…๋ฃŒ ์กฐ๊ฑด์ด ๊ฐ€๋…์„ฑ์ด ๋–จ์–ด์ ธ ๋ณด์—ฌ์„œ ์ง์ ‘ ์ž‘์„ฑํ•˜์ง€ ๋ง๊ณ  flag๋กœ ๋Œ€์ฒดํ•ด์•ผ๊ฒ ๋‹ค๋Š” ์ƒ๊ฐ์„ ํ–ˆ๋‹ค.

 

# ๋‚˜์˜ ํ’€์ด
n = int(input())
number = 665
result = []

while not len(result) >= n:
    if str(number).count('666') >= 1:
        result.append(number)
    number+=1

print(result[n-1])
# ๋‹ค๋ฅธ์‚ฌ๋žŒ์˜ ํ’€์ด
n = int(input())
number = 665
flag = True
cnt = 0

while flag:
    if '666' in str(number):
        cnt += 1
        print(cnt, number)

    if n == cnt:
        flag = False
    else:
        number+=1
print(number)
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€