Coding/Code in the Morning

211126_Code in the morning

๊น€์œ ๋‹ˆ์ฝ˜ 2021. 11. 26. 11:36

 

์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์ˆ˜๋ฐ•์ˆ˜๋ฐ•์ˆ˜๋ฐ•์ˆ˜๋ฐ•์ˆ˜๋ฐ•์ˆ˜?

๊ธธ์ด๊ฐ€ n์ด๊ณ , "์ˆ˜๋ฐ•์ˆ˜๋ฐ•์ˆ˜๋ฐ•์ˆ˜...."์™€ ๊ฐ™์€ ํŒจํ„ด์„ ์œ ์ง€ํ•˜๋Š” ๋ฌธ์ž์—ด์„ ๋ฆฌํ„ดํ•˜๋Š” ํ•จ์ˆ˜, solution์„ ์™„์„ฑํ•˜์„ธ์š”. ์˜ˆ๋ฅผ๋“ค์–ด n์ด 4์ด๋ฉด "์ˆ˜๋ฐ•์ˆ˜๋ฐ•"์„ ๋ฆฌํ„ดํ•˜๊ณ  3์ด๋ผ๋ฉด "์ˆ˜๋ฐ•์ˆ˜"๋ฅผ ๋ฆฌํ„ดํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค. ์ œํ•œ

programmers.co.kr

๐Ÿ’ฌ ๋ฌธ์ œ ์„ค๋ช…

๊ธธ์ด๊ฐ€ n์ด๊ณ , "์ˆ˜๋ฐ•์ˆ˜๋ฐ•์ˆ˜๋ฐ•์ˆ˜...."์™€ ๊ฐ™์€ ํŒจํ„ด์„ ์œ ์ง€ํ•˜๋Š” ๋ฌธ์ž์—ด์„ ๋ฆฌํ„ดํ•˜๋Š” ํ•จ์ˆ˜, solution์„ ์™„์„ฑํ•˜์„ธ์š”. ์˜ˆ๋ฅผ๋“ค์–ด n์ด 4์ด๋ฉด "์ˆ˜๋ฐ•์ˆ˜๋ฐ•"์„ ๋ฆฌํ„ดํ•˜๊ณ  3์ด๋ผ๋ฉด "์ˆ˜๋ฐ•์ˆ˜"๋ฅผ ๋ฆฌํ„ดํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

 

 

๐Ÿ“ ์ œํ•œ ์‚ฌํ•ญ

  • n์€ ๊ธธ์ด 10,000์ดํ•˜์ธ ์ž์—ฐ์ˆ˜์ž…๋‹ˆ๋‹ค.

 

 

๐Ÿ’ก ๋‚˜์˜ ํ’€์ด 

def solution(n):
    answer = ''
    for i in range(0, n):
        if i % 2 == 0:
            answer += '์ˆ˜'
        else:
            answer += '๋ฐ•'

    return answer

 

 

๐Ÿ’ก ๋‹ค๋ฅธ ํ•ด์„ค

def water_melon(n):
    return ("์ˆ˜๋ฐ•"*n)[0:n]

 

 

???

์ฝœ๋กฌ๋ฒ„์Šค ๊ณ„๋ž€๊นจ๊ธฐ ๋Š๋‚Œ์ด ์ด๋Ÿฐ๊ฑด๊ฐ€

 

 

 

 

 

 

 

 

 


 

 

์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์„œ์šธ์—์„œ ๊น€์„œ๋ฐฉ ์ฐพ๊ธฐ

Stringํ˜• ๋ฐฐ์—ด seoul์˜ element์ค‘ "Kim"์˜ ์œ„์น˜ x๋ฅผ ์ฐพ์•„, "๊น€์„œ๋ฐฉ์€ x์— ์žˆ๋‹ค"๋Š” String์„ ๋ฐ˜ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜, solution์„ ์™„์„ฑํ•˜์„ธ์š”. seoul์— "Kim"์€ ์˜ค์ง ํ•œ ๋ฒˆ๋งŒ ๋‚˜ํƒ€๋‚˜๋ฉฐ ์ž˜๋ชป๋œ ๊ฐ’์ด ์ž…๋ ฅ๋˜๋Š” ๊ฒฝ์šฐ๋Š” ์—†์Šต๋‹ˆ

programmers.co.kr

๐Ÿ’ฌ ๋ฌธ์ œ ์„ค๋ช…

Stringํ˜• ๋ฐฐ์—ด seoul์˜ element์ค‘ "Kim"์˜ ์œ„์น˜ x๋ฅผ ์ฐพ์•„, "๊น€์„œ๋ฐฉ์€ x์— ์žˆ๋‹ค"๋Š” String์„ ๋ฐ˜ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜, solution์„ ์™„์„ฑํ•˜์„ธ์š”. seoul์— "Kim"์€ ์˜ค์ง ํ•œ ๋ฒˆ๋งŒ ๋‚˜ํƒ€๋‚˜๋ฉฐ ์ž˜๋ชป๋œ ๊ฐ’์ด ์ž…๋ ฅ๋˜๋Š” ๊ฒฝ์šฐ๋Š” ์—†์Šต๋‹ˆ๋‹ค.

 

 

๐Ÿ“ ์ œํ•œ ์‚ฌํ•ญ

  • seoul์€ ๊ธธ์ด 1 ์ด์ƒ, 1000 ์ดํ•˜์ธ ๋ฐฐ์—ด์ž…๋‹ˆ๋‹ค.
  • seoul์˜ ์›์†Œ๋Š” ๊ธธ์ด 1 ์ด์ƒ, 20 ์ดํ•˜์ธ ๋ฌธ์ž์—ด์ž…๋‹ˆ๋‹ค.
  • "Kim"์€ ๋ฐ˜๋“œ์‹œ seoul ์•ˆ์— ํฌํ•จ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.

 

 


 

๐Ÿ’ก ๋‚˜์˜ ํ’€์ด

 

def solution(seoul):
    answer = ''
    
    x = seoul.index('Kim')
    answer = '๊น€์„œ๋ฐฉ์€ ' + str(x) +'์— ์žˆ๋‹ค'
    
    return answer

 

 

'Coding > Code in the Morning' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

211206_Code at Night โญ๏ธ  (0) 2021.12.06
211129_Code in the morning  (0) 2021.11.29
211123_Code int the morning  (0) 2021.11.23
211103_Code in the morning  (0) 2021.11.03
211101_Code in the morning  (0) 2021.11.01