Potato
์•ˆ๋…•ํ•˜์„ธ์š”, ๊ฐ์žก๋‹ˆ๋‹ค?๐Ÿฅ” ^___^ ๐Ÿ˜บ github ๋ฐ”๋กœ๊ฐ€๊ธฐ ๐Ÿ‘‰๐Ÿป

Algorithm/Baekjoon

[python3] ์ด์ฝ”ํ…Œ - ๋ฌธ์ž์—ด ์žฌ์ •๋ ฌ (ch.12 ๊ตฌํ˜„ - ์œ ํ˜•๋ณ„ ๊ธฐ์ถœ๋ฌธ์ œ)

๊ฐ์ž ๐Ÿฅ” 2021. 6. 23. 21:19
๋ฐ˜์‘ํ˜•

์ฐธ๊ณ ) ์ด๊ฒƒ์ด ์ทจ์—…์„ ์œ„ํ•œ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ๋‹ค with ํŒŒ์ด์ฌ ์ฑ…์„ ๊ธฐ๋ฐ˜์œผ๋กœ ์ž‘์„ฑ๋œ ๋ฌธ์ œ์™€ ์ฝ”๋“œ์ž…๋‹ˆ๋‹ค. 
๋”ฐ๋ผ์„œ ๋ฌธ์ œ๋Š” ์ž์„ธํ•˜๊ฒŒ ์ ์ง€ ์•Š๊ณ , ๊ฐ„๋‹จํ•œ ์„ค๋ช…๊ณผ ์ œ ์ฝ”๋“œ๋งŒ ์˜ฌ๋ฆฌ๊ฒ ์Šต๋‹ˆ๋‹ค.

 

๋ฌธ์ž์—ด ์žฌ์ •๋ ฌ (ebook ๊ธฐ์ค€ p.324)

- ์•ŒํŒŒ๋ฒณ ๋Œ€๋ฌธ์ž์™€ ์ˆซ์ž (0~9)๋กœ๋งŒ ๊ตฌ์„ฑ๋œ ๋ฌธ์ž์—ด์ด ์ž…๋ ฅ์œผ๋กœ ์ฃผ์–ด์ง.
- ์ด๋•Œ ๋ชจ๋“  ์•ŒํŒŒ๋ฒณ์„ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•˜์—ฌ ์ด์–ด์„œ ์ถœ๋ ฅํ•œ ๋’ค, ๊ทธ ๋’ค ๋ชจ๋“  ์ˆซ์ž์˜ ํ•ฉ์„ ์ถœ๋ ฅ
- K1KA5CB7 ์ด๋ฉด ABCKK13์ด ์ถœ๋ ฅ๋˜์–ด์•ผํ•จ

##### ์ž…๋ ฅ์กฐ๊ฑด
์ฒซ์จ‹์ค„์— ํ•˜๋‚˜์˜ ๋ฌธ์ž์—ด S๊ฐ€ ์ฃผ์–ด์ง. (1<=S<=10,000)

 

<๋‚˜์˜ ํ’€์ด : ๋งž์Œ>

s = input()
num_list = ['0','1','2','3','4','5','6','7','8','9']

def solution(s,num_list):
    num = [] 
    
    s = sorted(s) #์ˆซ์ž๋ถ€ํ„ฐ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌ๋จ
    while True:
        if s[0] in num_list:
            num.append(s.pop(0))
        else:
            break
    num = str(sum(list(map(int, num)))) #์ˆซ์žํ•ฉ ๊ตฌํ•ด๋†“๊ธฐ
    
    st = '' #๋ฌธ์žํ•ฉ ๊ตฌํ•˜๊ธฐ
    for i in range(len(s)):
        st += s[i]
    
    answer = st+num  #๋ฌธ์ž+์ˆซ์ž str์œผ๋กœ ์ถœ๋ ฅ
    return answer

solution(s, num_list)
๋ฐ˜์‘ํ˜•