Tinkerbell Glitter
[241217] ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ž…๋ฌธ ๋ฌธ์ œ
[SPARTA] AI 9 (24.11 ~ 25.03) ๐Ÿƒ๐Ÿป‍โ™€๏ธ/๋ฌธ์ œ ํ’€์ด ๐Ÿ’ฏ
ํ”ผ์ž ๋‚˜๋ˆ  ๋จน๊ธฐ (2) Q. ๋จธ์“ฑ์ด๋„ค ํ”ผ์ž๊ฐ€๊ฒŒ๋Š” ํ”ผ์ž๋ฅผ ์—ฌ์„ฏ ์กฐ๊ฐ์œผ๋กœ ์ž˜๋ผ ์ค๋‹ˆ๋‹ค. ํ”ผ์ž๋ฅผ ๋‚˜๋ˆ ๋จน์„ ์‚ฌ๋žŒ์˜ ์ˆ˜`n` ์ด ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ,`n` ๋ช…์ด ์ฃผ๋ฌธํ•œ ํ”ผ์ž๋ฅผ ๋‚จ๊ธฐ์ง€ ์•Š๊ณ  ๋ชจ๋‘ ๊ฐ™์€ ์ˆ˜์˜ ํ”ผ์ž ์กฐ๊ฐ์„ ๋จน์–ด์•ผ ํ•œ๋‹ค๋ฉด ์ตœ์†Œ ๋ช‡ ํŒ์„ ์‹œ์ผœ์•ผ ํ•˜๋Š”์ง€๋ฅผ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด๋ณด์„ธ์š”.A.def gcd(a, b): # ํ•œ ๋ฒˆ ์“ฐ๊ณ  ๋ฒ„๋ ค์งˆ ์ตœ๋Œ€๊ณต์•ฝ์ˆ˜ ํ•จ์ˆ˜ ํ˜ธ์ถœํ•ด์ค๋‹ˆ๋‹ค... while b: a, b= b, a % b return adef lcm(a, b): # ์ตœ์†Œ๊ณต๋ฐฐ์ˆ˜๋ฅผ ์œ„ํ•ด ์ตœ๋Œ€๊ณต์•ฝ์ˆ˜๋ฅผ ์ƒ์„ฑํ•œ ๋‚˜... ์•„์ด๊ณ  ๋น„ํšจ์œจ์ ์ด๋‹ค... return (a * b) // gcd(a, b)def solution(n): nanum = n // 6 namuji..
[241217] ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ž…๋ฌธ ๋ฌธ์ œ
[SPARTA] AI 9 (24.11 ~ 25.03) ๐Ÿƒ๐Ÿป‍โ™€๏ธ/๋ฌธ์ œ ํ’€์ด ๐Ÿ’ฏ
์ตœ๋นˆ๊ฐ’ ๊ตฌํ•˜๊ธฐQ. ์ตœ๋นˆ๊ฐ’์€ ์ฃผ์–ด์ง„ ๊ฐ’ ์ค‘์—์„œ ๊ฐ€์žฅ ์ž์ฃผ ๋‚˜์˜ค๋Š” ๊ฐ’์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. ์ •์ˆ˜ ๋ฐฐ์—ด `array` ๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ,์ตœ๋นˆ๊ฐ’์„ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด๋ณด์„ธ์š”. ์ตœ๋นˆ๊ฐ’์ด ์—ฌ๋Ÿฌ ๊ฐœ๋ฉด -1์„ return ํ•ฉ๋‹ˆ๋‹ค.A.from collections import Counter # ์ปฌ๋ ‰์…˜ ๋ชจ๋“ˆ์˜ ์นด์šดํ„ฐ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์˜€์Šต๋‹ˆ๋‹ค.def solution(array): # ์ธ์ž๋ฅผ array๋กœ ๋ฐ›๋Š” solution ํ•จ์ˆ˜ ํ˜ธ์ถœ # Counter ํ•จ์ˆ˜๋Š” ๋ฆฌ์ŠคํŠธ์˜ ์š”์†Œ(key:array)๊ฐ€ ๋ช‡ ๋ฒˆ ๋‚˜์˜ค๋Š”์ง€(value)๋ฅผ dict ํ˜•ํƒœ๋กœ ์ €์žฅ ๋ฐ›์Šต๋‹ˆ๋‹ค. array_count = Counter(array) # array_count ๋ณ€์ˆ˜์— Counter(array)๋ฅผ ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค. ma..
[241212] ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ž…๋ฌธ ๋ฌธ์ œ
[SPARTA] AI 9 (24.11 ~ 25.03) ๐Ÿƒ๐Ÿป‍โ™€๏ธ/๋ฌธ์ œ ํ’€์ด ๐Ÿ’ฏ
์‚ผ๊ฐํ˜•์˜ ์™„์„ฑ์กฐ๊ฑดQ. ์‚ผ๊ฐํ˜•์˜ ์„ธ ๋ณ€์˜ ๊ธธ์ด๊ฐ€ ๋‹ด๊ธด ๋ฐฐ์—ด `sides` ์ด ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. ์„ธ ๋ณ€์œผ๋กœ ์‚ผ๊ฐํ˜•์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค๋ฉด 1, ๋งŒ๋“ค ์ˆ˜ ์—†๋‹ค๋ฉด 2๋ฅผ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. # ์ฃผ์„์ฒ˜๋ฆฌ ๋œ ์ฝ”๋“œ๋“ค์€ ์ˆ˜์ • ์ „ ๊ธฐ์กด ์ฝ”๋“œ ์ž…๋‹ˆ๋‹ค.def solution(sides): #answer = sides minusdata: return 2 elif in_max ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์— ์žˆ๋˜ ํƒ€์ธ๋“ค์˜ ๋ฌธ์ œํ’€์ด:1.def solution(sides): # ์ปดํ”„๋ฆฌํ•ธ์…˜ return 1 if max(sides)  2.def solution(sides): sides.sort() return 1 if sides[0]+sides[1]>sides[2] els..
[241211] ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ž…๋ฌธ ๋ฌธ์ œ
[SPARTA] AI 9 (24.11 ~ 25.03) ๐Ÿƒ๐Ÿป‍โ™€๏ธ/๋ฌธ์ œ ํ’€์ด ๐Ÿ’ฏ
๋‚˜์ด ์ถœ๋ ฅํ•˜๊ธฐQ. ๋จธ์“ฑ์ด๋Š” ์„ ์ƒ๋‹˜์ด ๋ช‡ ๋…„๋„์— ํƒœ์–ด๋‚ฌ๋Š”์ง€ ๊ถ๊ธˆํ•ด์กŒ์Šต๋‹ˆ๋‹ค. 2022๋…„ ๊ธฐ์ค€ ์„ ์ƒ๋‹˜์˜ ๋‚˜์ด age ๊ฐ€ ์ฃผ์–ด์งˆ ๋•Œ,์„ ์ƒ๋‹˜์˜ ์ถœ์ƒ ์—ฐ๋„๋ฅผ return ํ•˜๋Š” solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”.A.def solution(age): answer = 0 answer = 2022 - age while age: answer += 1 return answer ์ฒ˜์Œ์— ์ฝ”๋“œ๋ฅผ ์งฐ์„ ๋•Œwhile๋ฌธ์„ ์‚ฌ์šฉํ•˜์—ฌ์„œ ์ฝ”๋“œ๋ฅผ ์งœ๋ดค๋Š”๋ฐ,๋ญ”๊ฐ€ if๋ฌธ์œผ๋กœ๋„ ์ฝ”๋“œ ์งœ๋ณผ ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์•„์„œif๋ฌธ ์ฝ”๋“œ๋„ ๋“ค๊ณ ์™€๋ด„def solution(age): answer = 0 answer = 2022 - age if age == age: answer += 1 r..
[241210] ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ž…๋ฌธ ๋ฌธ์ œ
[SPARTA] AI 9 (24.11 ~ 25.03) ๐Ÿƒ๐Ÿป‍โ™€๏ธ/๋ฌธ์ œ ํ’€์ด ๐Ÿ’ฏ
1. ๋ถ„์ˆ˜์˜ ๋ง์…ˆQ. ์ฒซ๋ฒˆ์งธ ๋ถ„์ˆ˜์˜ ๋ถ„์ž์™€ ๋ถ„๋ชจ๋ฅผ ๋œปํ•˜๋Š” numer1, denom1, ๋‘๋ฒˆ์งธ ๋ถ„์ˆ˜์˜ ๋ถ„์ž์™€ ๋ถ„๋ชจ๋ฅผ ๋œปํ•˜๋Š” numer2, denom2 ๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. ๋‘ ๋ถ„์ˆ˜๋ฅผ ๋”ํ•œ ๊ฐ’์„ ๊ธฐ์•ฝ ๋ถ„์ˆ˜๋กœ ๋‚˜ํƒ€๋‚ด์—ˆ์„ ๋•Œ, ๋ถ„์ž์™€ ๋ถ„๋ชจ๋ฅผ ์ˆœ์„œ๋Œ€๋กœ ๋‹ด์€ ๋ฐฐ์—ด์„ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด๋ณด์„ธ์š”.A. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค๋Š” ๋ชจ๋“ˆ ์ ์šฉ์ด ์•ˆ๋˜๋‹ˆ๊นŒ ์ผ์ผ์ด ๊ตฌํ˜„์„ ํ•ด์ค˜์•ผ ํ•˜๋Š”๋ฐ,์–ด๋–ป๊ฒŒ ํ•ด์ค˜์•ผ ํ•˜๋Š”์ง€ ๋ชจ๋ฅด๋‹ˆ๊นŒ ์ผ๋‹จ ๋ณด๋ผ์„ ์ƒํ•œํ…Œ ๋ฌผ์–ด๋ด์„œ ์–ป์€ ์ฝ”๋“œ๋ฅผ ๋ฐ๋ ค์™€๋ดค์Šต๋‹ˆ๋‹ค.def gcd(a, b): while b: a, b = b, a % b return adef lcm(a, b): return a * b // gcd(a, b)def solution(numer1, denom1, nu..
[241127] ์ดˆ๋ณด๋ฅผ ์œ„ํ•œ ํŒŒ์ด์ฌ 300์ œ ์—ฐ์Šต
[SPARTA] AI 9 (24.11 ~ 25.03) ๐Ÿƒ๐Ÿป‍โ™€๏ธ/๋ฌธ์ œ ํ’€์ด ๐Ÿ’ฏ
์˜ค๋Š˜์€ ์ดˆ๋ณด๋ฅผ ์œ„ํ•œ ํŒŒ์ด์ฌ 300์ œ ๋ฌธ์ œ๋ฅผ ํ’€์–ด๋ณด์•˜์๋‹ˆ๋‹ค๋„ˆ๋ฌด ๋ฐฐ๊ณ ํ”„๊ณ ,,, ์กธ๋ฆฌ๋„ค์š”,,, ์ดˆ๋ณด๋ฅผ ์œ„ํ•œ ํŒŒ์ด์ฌ 300์ œํ—ฌ๋กœ์›”๋“œ ์ถœ๋ ฅํ–ˆ์–ด์•ผ ํ–ˆ๋Š”๋ฐ,, ์–ด์ฉŒ๋‹ค๋ณด๋‹ˆ ํ—ฌ๋กœ๋งŒ ์ถœ๋ ฅํ•˜๊ฒŒ ๋จ ใ…‹ํฐ๋”ฐ ์•ˆ์— ์ž‘๋”ฐ ๋ฌธ์ œ ์—†์ฃ ?ํฐ๋”ฐ ์•ˆ์— ํฐ๋”ฐ๋Š” ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜๋‹ˆ ์ž‘๋”ฐ๋กœ ๋ณ€๊ฒฝํ•ด์ฃผ์—ˆ์–ด์š”.๊ฒฐ๊ณผ ์ถœ๋ ฅ๋ฌผ์„naver;kakao;sk;samsung ์„ ์ถœ๋ ฅํ•˜๋Š” ๊ฑฐ์˜€๋Š”๋ฐ,๋‚œ ๋„ˆ๋ฌด ๋‹จ์ˆœํ•˜๊ฒŒ ์ƒ๊ฐํ•˜๋Š” ๋ฐ”๋žŒ์—print("naver;kakao;sk;samsung") ์ด๋ผ๊ณ  ์ผ์ผ์ด ๋‹ค์ ์–ด๋ฒ„๋ฆผใ…‹ใ…‹ใ…‹ใ…‹๊ทผ๋ฐ ์ •๋‹ต์—์„œ๋Š”print("naver", "kakao", "sk", "samsung", sep = ";") ๋ผ๊ณ  ์ ํ˜€์žˆ์—ˆ๋Š”๋ฐ์š”~์‘๋‚œ์ดˆ๋ณด๊ฐœ๋ฐœ์ž~ ์•„์ง๋ฉ€์—ˆ์ง€~์‚ฌ์‹ค sep ๊ธฐ๋Šฅ์„ ๋ชฐ๋ผ์„œ ์ฑ—์ง€ํ”ผํ‹ฐ์— ๊ฒ€์ƒ‰ํ•ด๋ด„.print() ํ•จ์ˆ˜์—์„œ sep ์ธ์ž๋Š” '์ถœ๋ ฅํ•  ๊ฐ’๋“ค ์‚ฌ์ด..