[Python] ๋ณ‘ํ•ฉ์ •๋ ฌ
ยท
Algorithm/Python
๋ณ‘ํ•ฉ์ •๋ ฌ ๋ฐ์ดํ„ฐ์˜ ์š”์†Œ๋“ค์„ ๋‘ ๊ทธ๋ฃน์œผ๋กœ ๋‚˜๋ˆˆ ํ›„ ์ •๋ ฌํ•˜๊ณ , ์ •๋ ฌ๋œ ๋‘ ๊ทธ๋ฃน์„ ๋น„๊ตํ•˜๋ฉฐ ํ•˜๋‚˜๋กœ ํ•ฉ์น˜๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด๋‹ค. ๋ณ‘ํ•ฉ์ •๋ ฌ๊ณผ์ • #์ˆซ์ž 8๊ฐœ๋ฅผ ๋ฐ˜์œผ๋กœ ๋‚˜๋ˆˆ๋‹ค group1 = [2, 8, 4, 7] group2 = [6, 1, 3, 5] #๋‘ ๊ทธ๋ฃน์„ ์ •๋ ฌํ•œ๋‹ค. group1 = [2, 4, 7, 8] group2 = [1, 3, 5, 6] #๋‘ ๊ทธ๋ฃน์„ ํ•˜๋‚˜์˜ ๊ทธ๋ฃน์œผ๋กœ ํ•ฉ์นœ๋‹ค. ๋‘ ๊ทธ๋ฃน์˜ ์ฒซ๋ฒˆ์งธ ๊ฐ’์„ ๋น„๊ตํ•ด ์ž‘์€ ๊ฐ’์„ ์ƒˆ๋กœ์šด ๋ฆฌ์ŠคํŠธ(result)์— ๋„ฃ๋Š”๋‹ค. group1 = [2, 4, 7, 8] group2 = [3, 5, 6] result = [1] #๋‘ ๊ทธ๋ฃน์˜ ์ฒซ๋ฒˆ์งธ ๊ฐ’์„ ๋น„๊ตํ•ด ์ž‘์€ ๊ฐ’์„ ์ƒˆ๋กœ์šด ๋ฆฌ์ŠคํŠธ์— ๋„ฃ๋Š” ๊ฒƒ์„ ๋ฐ˜๋ณตํ•œ๋‹ค. group1 = [4, 7, 8] group2 = [3, 5, 6] result ..
[Python] ๋ฐฑ์ค€ 1427 - ์†ŒํŠธ์ธ์‚ฌ์ด๋“œ
ยท
Algorithm
๋ฌธ์ œ ๋ฐฐ์—ด์„ ์ •๋ ฌํ•˜๋Š” ๊ฒƒ์€ ์‰ฝ๋‹ค. ์ˆ˜๊ฐ€ ์ฃผ์–ด์ง€๋ฉด, ๊ทธ ์ˆ˜์˜ ๊ฐ ์ž๋ฆฌ์ˆ˜๋ฅผ ๋‚ด๋ฆผ์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•ด๋ณด์ž. ์ž…๋ ฅ ์ฒซ์งธ ์ค„์— ์ •๋ ฌํ•˜๊ณ ์žํ•˜๋Š” ์ˆ˜ N์ด ์ฃผ์–ด์ง„๋‹ค. N์€ 1,000,000,000๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜์ด๋‹ค. ์ถœ๋ ฅ ์ฒซ์งธ ์ค„์— ์ž๋ฆฌ์ˆ˜๋ฅผ ๋‚ด๋ฆผ์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•œ ์ˆ˜๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. ์ •๋‹ต n = int(input()) a = list(str(n)) a.sort() a.reverse() for n in a: print(n, end="") n์„ ์ž…๋ ฅ๋ฐ›๊ณ  a๋ผ๋Š” ๋ฆฌ์ŠคํŠธ๋ฅผ ๋งŒ๋“ค์–ด ์ €์žฅํ•œ๋‹ค. sort()ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•ด ์ •๋ ฌํ•˜๊ณ , reverse()ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•ด ๋’ค์ง‘๋Š”๋‹ค. for๋ฌธ์„ ์ด์šฉํ•ด ์ถœ๋ ฅํ•œ๋‹ค.
[Python] ์„ ํƒ์ •๋ ฌ
ยท
Algorithm/Python
์„ ํƒ์ •๋ ฌ ๋ฐ์ดํ„ฐ์—์„œ ์ตœ์†Ÿ๊ฐ’์„ ์ฐพ์•„ ๊ทธ ๊ฐ’๊ณผ ๋ฒ”์œ„์˜ ๋งจ ์•ž์— ์žˆ๋Š” ๊ฐ’์„ ์„œ๋กœ ๋ฐ”๊พธ๋Š” ๊ณผ์ •์„ ๋ฐ˜๋ณตํ•˜๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด๋‹ค. ์„ ํƒ์ •๋ ฌ ๊ณผ์ • ์˜ˆ๋ฅผ ๋“ค์–ด [2, 4, 5, 1, 3] ๊ฐ€ ์žˆ์„ ๋•Œ, ๊ฐ€์žฅ ์ž‘์€ ๊ฐ’์„ ์ฐพ์•„ ์ฒซ๋ฒˆ์งธ ๊ฐ’๊ณผ ๊ทธ ๊ฐ’์„ ๋ฐ”๊พผ๋‹ค. (์ด๋ฏธ ์ •๋ ฌ ์™„๋ฃŒ๋œ ๊ฐ’์€ | ๋กœ ๊ตฌ๋ถ„ํ•œ๋‹ค.) [2, 4, 5, 1, 3] # ๊ฐ€์žฅ ์ž‘์€ ๊ฐ’ : 1 ์ฒซ๋ฒˆ์งธ ๊ฐ’ : 2 [1 | 4, 5, 2, 3] # ๊ฐ€์žฅ ์ž‘์€ ๊ฐ’ : 2 ์ฒซ๋ฒˆ์งธ ๊ฐ’ : 4 [1, 2 | 5, 4, 3] # ๊ฐ€์žฅ ์ž‘์€ ๊ฐ’ : 3 ์ฒซ๋ฒˆ์งธ ๊ฐ’ : 5 [1, 2, 3 | 4, 5] # ๊ฐ€์žฅ ์ž‘์€ ๊ฐ’ : 4 ์ฒซ๋ฒˆ์งธ ๊ฐ’ : 4 //๋ณ€ํ™”์—†์Œ [1, 2, 3, 4 | 5] # ์ž๋ฃŒ๊ฐ€ 5 ํ•˜๋‚˜๋งŒ ๋‚จ์Œ. ์ข…๋ฃŒ ๊ฒฐ๊ณผ [1, 2, 3, 4, 5] ์„ ํƒ์ •๋ ฌ ์•Œ๊ณ ๋ฆฌ์ฆ˜ def sel_..