๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
728x90
๋ฐ˜์‘ํ˜•

KAKAO18

[Swift] 2022 KAKAO TECH INTERNSHIP ๋“ฑ์‚ฐ์ฝ”์Šค ์ •ํ•˜๊ธฐ Problem ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr Solution ํ•ด๋‹น ๋ฌธ์ œ๋Š” BFS ํ˜น์€ ๋‹ค์ต์ŠคํŠธ๋ผ๋ฅผ ์ด์šฉํ•˜์—ฌ ํ’€์–ด์•ผ ํ•˜๋Š” ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค. 1. ํ˜„์žฌ ๊ฒฝ๋กœ์˜ ์ตœ๋Œ€ intensity์™€ ํ˜„์žฌ ์ง€์ ์˜ ์ •๋ณด๋ฅผ ๊ฐ–๋Š” Node๋ฅผ ๋งŒ๋“ค์–ด ์ค€๋‹ค. struct Node { let current: Int let maxIntensity: Int } 2. ํ•„์š”ํ•œ ๋ณ€์ˆ˜๋“ค์„ ์„ธํŒ…ํ•ด ์ค€๋‹ค. answer: ๊ฐ€์žฅ ์ ์€ intensity์˜ ์‚ฐ๋ด‰์šฐ๋ฆฌ์™€ ๊ฐ’์„ ์ €์žฅํ•  ๋ณ€์ˆ˜ connection: path์˜ ์—ฐ๊ฒฐ๋œ ์ •๋ณด๋ฅผ ์ €์žฅํ•  ๋ณ€์ˆ˜ summitDic: ์‚ฐ๋ด‰์šฐ๋ฆฌ๋ฅผ ์ €์žฅํ•  ๋”•์…”๋„ˆ๋ฆฌ gat.. 2022. 8. 29.
[Swift] 2022 KAKAO TECH INTERNSHIP ์ฝ”๋”ฉ ํ…Œ์ŠคํŠธ ๊ณต๋ถ€ Problem ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr Solution ํ•ด๋‹น ๋ฌธ์ œ๋Š” ๋‹ค์ด๋‚˜๋ฏน ํ”„๋กœ๊ทธ๋ž˜๋ฐ์œผ๋กœ ํ’€์–ด์•ผ ํ•˜๋Š” ๋ฌธ์ œ์ด๋‹ค. 1. ์•Œ๊ณ ๋ ฅ๊ณผ ์ฝ”๋”ฉ๋ ฅ์˜ ์ตœ๋Œ€์น˜๋ฅผ ๊ตฌํ•ด์ค€๋‹ค. ๋ฌธ์ œ๋ฅผ ๋ชจ๋‘ ํ’€ ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฒƒ์€ ์•Œ๊ณ ๋ ฅ๊ณผ ์ฝ”๋”ฉ๋ ฅ์˜ ์ตœ๋Œ€์น˜๋ฅผ ์–ป๋Š” ๋‹ค๋Š” ๊ฒƒ์ด๋ฏ€๋กœ ๋ฏธ๋ฆฌ ๊ตฌํ•ด์ค€๋‹ค. var maxAlp: Int = alp var maxCop: Int = cop problems.forEach { maxAlp = max(maxAlp,$0[0]) maxCop = max(maxCop,$0[1]) } 2. dp ๋ฐฐ์—ด์„ ์•Œ๊ณ ๋ ฅ + 1 , ์ฝ”๋”ฉ๋ ฅ + 1๊ฐœ์˜ ์ด์ค‘ ๋ฐฐ์—ด์„ ๋งŒ๋“ค์–ด .. 2022. 8. 26.
[Swift] 2022 KAKAO TECH INTERNSHIP ๋‘ ํ ํ•ฉ ๊ฐ™๊ฒŒ ๋งŒ๋“ค๊ธฐ Problem ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr Solution ๋‚˜๋Š” ์ด๋ฒˆ ๋ฌธ์ œ๋ฅผ ์Šฌ๋ผ์ด๋”ฉ ์œˆ๋„์šฐ(Sliding-Window)๋ฅผ ์ด์šฉํ•ด์„œ ํ’€์—ˆ๋‹ค. 1. ํ•„์š”ํ•œ ๋ณ€์ˆ˜๋ฅผ ์„ธํŒ…ํ•œ๋‹ค. cumulativeSum: ๋ˆ„์ ํ•ฉ์„ ๋‹ด์„ ๋ฐฐ์—ด q1Length: queue1์˜ ๊ธธ์ด q2Length: queue2์˜ ๊ธธ์ด answer: ๊ฐ€์žฅ ์ ์€ ์ž‘์—… ํšŸ์ˆ˜๋ฅผ ๊ธฐ๋กํ•  ๋ณ€์ˆ˜ start: ์Šฌ๋ผ์ด๋”ฉ ์œˆ๋„์šฐ์—์„œ ์‹œ์ž‘ ์ง€์ ์„ ๊ฐ€๋ฅดํ‚ฌ ๋ณ€์ˆ˜ var cumulativeSum: [Int] = [0] let q1Length: Int = queue1.count let q2Length: I.. 2022. 8. 24.
[Swift] 2022 KAKAO TECH INTERNSHIP ์„ฑ๊ฒฉ ์œ ํ˜• ๊ฒ€์‚ฌํ•˜๊ธฐ Problem ํ•œ ๋™์•ˆ ๋ฆฟ์ฝ”๋“œ๋งŒ ํ’€๋‹ค๊ฐ€ ์ •๋ง ์˜ค๋žœ๋งŒ์— ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค๋ฅผ ๋“ค์–ด๊ฐ”๋”๋‹ˆ ์ƒˆ๋กœ์šด ์นด์นด์˜ค ๋ฌธ์ œ๊ฐ€ ์žˆ์–ด์„œ ํ•œ๋ฒˆ ํ’€์–ด๋ดค๋‹ค. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr Solution 1. ์ฃผ์–ด์ง„ ์„ฑ๊ฒฉ ์•ŒํŒŒ๋ฒณ์„ ๋”•์…”๋„ˆ๋ฆฌ๋กœ ๋งŒ๋“ค์–ด ์ค€๋‹ค. var charDic: [Character:Int] = ["R":0,"T":0,"C":0,"F":0,"J":0,"M":0,"A":0,"N":0] 2. survey๋ฅผ ์ˆœํšŒํ•˜๋ฉฐ choice์˜ ๊ฐ’์— ๋งž๊ฒŒ ์ฒซ ๋ฒˆ์งธ ๋˜๋Š” ๋‘ ๋ฒˆ์งธ ์บ๋ฆญํ„ฐ์— ๊ฐ’์„ ๋”ํ•ด์ค€๋‹ค. ๋งŒ์•ฝ choices์˜ i๋ฒˆ์งธ ๊ฐ’์ด 4๋ณด๋‹ค ์ž‘๋‹ค๋ฉด ์ฒซ ๋ฒˆ์งธ ๊ธ€์ž์— 4์—์„œ ํ•ด๋‹น.. 2022. 8. 23.
[Swift] 2019 KAKAO BLIND RECRUITMENT ๋ธ”๋ก ๊ฒŒ์ž„ Problem ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ๋ธ”๋ก ๊ฒŒ์ž„ [[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,4,0,0,0],[0,0,0,0,0,4,4,0,0,0],[0,0,0,0,3,0,4,0,0,0],[0,0,0,2,3,0,0,0,5,5],[1,2,2,2,3,3,0,0,0,5],[1,1,1,0,0,0,0,0,0,5]] 2 programmers.co.kr Solution 1. ๋จผ์ € ๊ฒ€์€ ๋ธ”๋ก์„ ๋–จ์–ด๋œจ๋ ค ์‚ญ์ œ๊ฐ€ ๊ฐ€๋Šฅํ•œ ๋ธ”๋ก๋“ค์„ ์ฐพ์•„๋‚ธ๋‹ค. ์ฃผ์–ด์ง„ ๋ธ”๋ก์€ ์ฐจ๋ก€๋Œ€๋กœ 1๋ฒˆ ๋ธ”๋ก์˜ 0,1,2,3 ํƒ€์ž…, 2๋ฒˆ ๋ธ”๋ก์˜ 0,1,2,3 ํƒ€์ž… , 3๋ฒˆ ๋ธ”๋ก์˜ 0,1,2,3ํƒ€์ž…์ด ์žˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•  ๋•Œ ๊ฒ€์€ ๋ธ”.. 2022. 3. 28.
[Swift] 2019 KAKAO WINTER INTERNSHIP ํ˜ธํ…” ๋ฐฉ ๋ฐฐ์ • Problem ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ํ˜ธํ…” ๋ฐฉ ๋ฐฐ์ • programmers.co.kr Solution 1. ์—ฐ์†๋œ ๋ฐฉ๋“ค์˜ ์‹œ์ž‘๊ณผ ๊ธธ์ด๋ฅผ ์ €์žฅํ•ด ๋†“์„ ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ ๋‹ค. ์ด ๋ฌธ์ œ์˜ ํ•ต์‹ฌ์€ ํˆฌ์ˆ™์„ ์›ํ•˜๋Š” ๋ฐฉ์ด ์ค‘๋ณต๋˜์—ˆ์„ ๋•Œ ํ•ด๋‹น ๋ฐฉ๋ณด๋‹ค ํฌ๋ฉด์„œ ๊ฐ€์žฅ ์ž‘์€ ๋ฐฉ์„ ์ฐพ๋Š” ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์— ์—ฐ์†๋œ ๋ฐฉ์˜ ๊ธธ์ด์™€ ์‹œ์ž‘๋œ ๋ฐฉ์˜ ์œ„์น˜๋ฅผ ๋”ํ•ด์ฃผ๋ฉด ์‰ฝ๊ฒŒ ์ฐพ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค๋ฉด 10๊ฐœ์˜ ๋ฐฉ ์ค‘ 2,3,4,5 ๊ฐ€ ์ด๋ฏธ ์ฐจ์žˆ๋‹ค๋ฉด ์‹œ์ž‘๋œ ๋ฐฉ์˜ ์œ„์น˜๋Š” 2์ด๊ณ  ์—ฐ์†๋œ ๋ฐฉ์˜ ๊ธธ์ด๋Š” 4์ž…๋‹ˆ๋‹ค. ๊ณ ๋กœ 2,3,4,5 ์ค‘์— ์ค‘๋ณต๋œ ๋ฐฉ์ด ์žˆ๋‹ค๋ฉด 2(์‹œ์ž‘๋œ ๋ฐฉ์˜ ์œ„์น˜) + 4(์—ฐ์†๋œ ๋ฐฉ์˜ ๊ธธ์ด) = 6์ด๋ฏ€๋กœ 6๋ฒˆ ๋ฐฉ์— ๋„ฃ์œผ๋ฉด ๋ฉ๋‹ˆ๋‹ค. class Room { var root:Int64,length:Int64 init(root:Int64,length:Int.. 2022. 2. 20.
[Swift] 2022 KAKAO BLIND RECRUITMENT ์‚ฌ๋ผ์ง€๋Š” ๋ฐœํŒ Problem ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์‚ฌ๋ผ์ง€๋Š” ๋ฐœํŒ [[1, 1, 1], [1, 1, 1], [1, 1, 1]] [1, 0] [1, 2] 5 [[1, 1, 1], [1, 0, 1], [1, 1, 1]] [1, 0] [1, 2] 4 programmers.co.kr Solution ํ•ด๋‹น ๋ฌธ์ œ๋Š” ์™„์ „ ํƒ์ƒ‰์œผ๋กœ ํ’€ ์ˆ˜ ์žˆ๋Š” ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค. 1. ํ”Œ๋ ˆ์ด์–ด์˜ ์œ„์น˜์™€ ๊ฒŒ์ž„ ๋๋‚ฌ์„ ๋•Œ ์›€์ง์ธ ํšŸ์ˆ˜์™€ ์Šน์ž๋ฅผ ์•Œ๋ ค์ค„ ๊ตฌ์กฐ์ฒด๋ฅผ ๋งŒ๋“ ๋‹ค. struct Location { var x:Int,y:Int } struct GameResult { var count:Int,isWinnerA:Bool } 2. board์˜ ๊ฐ€์žฅ ์ž๋ฆฌ๋ฅผ 0์œผ๋กœ ๊ฐ์‹ธ์ค€๋‹ค. Index out of range ์˜ค๋ฅ˜๋ฅผ ์‰ฝ๊ฒŒ ํ”ผํ•˜๊ธฐ ์œ„ํ•ด์„œ ์ž…๋‹ˆ๋‹ค. func wrapBoard.. 2022. 1. 20.
[Swift] 2022 KAKAO BLIND RECRUITMENT ํŒŒ๊ดด๋˜์ง€ ์•Š์€ ๊ฑด๋ฌผ Problem ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ํŒŒ๊ดด๋˜์ง€ ์•Š์€ ๊ฑด๋ฌผ [[5,5,5,5,5],[5,5,5,5,5],[5,5,5,5,5],[5,5,5,5,5]] [[1,0,0,3,4,4],[1,2,0,2,3,2],[2,1,0,3,1,2],[1,0,1,3,3,1]] 10 [[1,2,3],[4,5,6],[7,8,9]] [[1,1,1,2,2,4],[1,0,0,1,1,2],[2,2,0,2,0,100]] 6 programmers.co.kr Solution ํ•ด๋‹น ๋ฌธ์ œ๋Š” ๋ˆ„์ ํ•ฉ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์ด์šฉํ•ด ํ’€์–ด์•ผ ํ•˜๋Š” ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค. (์ž์„ธํ•œ ์„ค๋ช…์€ ์นด์นด์˜ค ๊ณต์‹ ํ•ด์„ค์„ ์ฐธ๊ณ ํ•˜๋ฉด ๋” ์ดํ•ดํ•˜๊ธฐ ์ˆ˜์›”ํ•˜์‹ค ๊ฑฐ์—์š”!) 1. board์—์„œ ์—ด๊ณผ ํ–‰์ด +1๋งŒํผ์˜ ํฌ๊ธฐ์˜ ์ƒˆ๋กœ์šด ๋ณด๋“œ๋ฅผ 0์œผ๋กœ ์ฑ„์›Œ์ค€๋‹ค. var zeroBoard = Array(repeating: .. 2022. 1. 20.
[Swift] 2022 KAKAO BLIND RECRUITMENT ์–‘๊ณผ ๋Š‘๋Œ€ Problem ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์–‘๊ณผ ๋Š‘๋Œ€ [0,0,1,1,1,0,1,0,1,0,1,1] [[0,1],[1,2],[1,4],[0,8],[8,7],[9,10],[9,11],[4,3],[6,5],[4,6],[8,9]] 5 [0,1,0,1,1,0,1,0,0,1,0] [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6],[3,7],[4,8],[6,9],[9,10]] 5 programmers.co.kr Solution ํ•ด๋‹น ๋ฌธ์ œ๋Š” ์™„์ „ํƒ์ƒ‰๊ณผ DFS๋กœ ํ’€์–ด์•ผ ํ•˜๋Š” ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค. 1. edge๋ฅผ ์ด์šฉํ•ด ๋ถ€๋ชจ์™€ ์ž์‹์„ ์—ฐ๊ฒฐํ•ด์ค๋‹ˆ๋‹ค. func connectEdge(_ edges:[[Int]]) { for edge in edges { if pc[edge[0]] == nil { pc[edge[0]] = [edg.. 2022. 1. 19.
[Swift] 2022 KAKAO BLIND RECRUITMENT ์–‘๊ถ๋Œ€ํšŒ Problem ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์–‘๊ถ๋Œ€ํšŒ ๋ฌธ์ œ ์„ค๋ช… ์นด์นด์˜ค๋ฐฐ ์–‘๊ถ๋Œ€ํšŒ๊ฐ€ ์—ด๋ ธ์Šต๋‹ˆ๋‹ค. ๋ผ์ด์–ธ์€ ์ €๋ฒˆ ์นด์นด์˜ค๋ฐฐ ์–‘๊ถ๋Œ€ํšŒ ์šฐ์Šน์ž์ด๊ณ  ์ด๋ฒˆ ๋Œ€ํšŒ์—๋„ ๊ฒฐ์Šน์ „๊นŒ์ง€ ์˜ฌ๋ผ์™”์Šต๋‹ˆ๋‹ค. ๊ฒฐ์Šน์ „ ์ƒ๋Œ€๋Š” ์–ดํ”ผ์น˜์ž…๋‹ˆ๋‹ค. ์นด์นด์˜ค๋ฐฐ ์–‘๊ถ๋Œ€ํšŒ ์šด์˜์œ„์› programmers.co.kr Solution ํ•ด๋‹น ๋ฌธ์ œ๋Š” DFS ๋ฐ ์™„์ „ํƒ์ƒ‰ ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค. 1. ๊ฐ ์ ์ˆ˜๋งˆ๋‹ค ์ด๊ธธ์ง€ ์งˆ์ง€๋ฅผ ๊ฒฐ์ •ํ•œ๋‹ค. 10์ ๋ถ€ํ„ฐ 1์ ๊นŒ์ง€ ์–ดํ”ผ์น˜๋ฅผ ์ด๊ธธ ์ˆ˜ ์žˆ๋Š”์ง€๋ฅผ ํŒ๋ณ„ํ•ฉ๋‹ˆ๋‹ค. ๋งŒ์•ฝ ์ด๊ธธ ์ˆ˜ ์žˆ๋‹ค๋ฉด ํ•ด๋‹น ์ ์ˆ˜๋ฅผ ์–ป๋Š” ๋ฐฉ๋ฒ•๊ณผ ๊ทธ๋ƒฅ 0๋ฐœ์„ ์ด์„œ ๋‹ค๋ฅธ ์ ์ˆ˜๋ฅผ ์–ป์„ ๋ฐฉ๋ฒ•์„ ํƒํ•ฉ๋‹ˆ๋‹ค. DFS๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์ด๊ธฐ๋Š” ๊ฒฝ์šฐ์™€ ๊ทธ๋ƒฅ 0๋ฐœ์„ ์˜๊ณ  ๋‹ค์Œ ๋‹จ๊ณ„๋กœ ๋„˜์–ด๊ฐˆ ๊ฒฝ์šฐ 2๊ฐ€์ง€๋ฅผ ์žฌ๊ท€ํ•ด์ค๋‹ˆ๋‹ค. func dfs(leftArrow:Int,depth:Int,history:[Int],info:[.. 2022. 1. 19.
[Swift] 2022 KAKAO BLIND RECRUITMENT ์ฃผ์ฐจ ์š”๊ธˆ ๊ณ„์‚ฐ Problem ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์ฃผ์ฐจ ์š”๊ธˆ ๊ณ„์‚ฐ [180, 5000, 10, 600] ["05:34 5961 IN", "06:00 0000 IN", "06:34 0000 OUT", "07:59 5961 OUT", "07:59 0148 IN", "18:59 0000 IN", "19:09 0148 OUT", "22:59 5961 IN", "23:00 5961 OUT"] [14600, 34400, 5000] programmers.co.kr Solution 1. records์˜ ๊ธฐ๋ก๋Œ€๋กœ ์‹œ๊ฐ„์„ ๊ณ„์‚ฐํ•ด ์ €์žฅํ•œ๋‹ค. var timeInfo:[String:Int] = [:] var parkInfo:[String:Int] = [:] func calTimeByRecord(_ records:[String],_ parkIn.. 2022. 1. 19.
[Swift] 2022 KAKAO BLIND RECRUITMENT k์ง„์ˆ˜์—์„œ ์†Œ์ˆ˜ ๊ฐœ์ˆ˜ ๊ตฌํ•˜๊ธฐ Problem ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - k์ง„์ˆ˜์—์„œ ์†Œ์ˆ˜ ๊ฐœ์ˆ˜ ๊ตฌํ•˜๊ธฐ ๋ฌธ์ œ ์„ค๋ช… ์–‘์˜ ์ •์ˆ˜ n์ด ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. ์ด ์ˆซ์ž๋ฅผ k์ง„์ˆ˜๋กœ ๋ฐ”๊ฟจ์„ ๋•Œ, ๋ณ€ํ™˜๋œ ์ˆ˜ ์•ˆ์— ์•„๋ž˜ ์กฐ๊ฑด์— ๋งž๋Š” ์†Œ์ˆ˜(Prime number)๊ฐ€ ๋ช‡ ๊ฐœ์ธ์ง€ ์•Œ์•„๋ณด๋ ค ํ•ฉ๋‹ˆ๋‹ค. 0P0์ฒ˜๋Ÿผ ์†Œ์ˆ˜ ์–‘์ชฝ์— 0์ด ์žˆ๋Š” ๊ฒฝ์šฐ P0์ฒ˜๋Ÿผ ์†Œ programmers.co.kr Solution 1. n์„ k์ง„์ˆ˜๋กœ ๋ฐ”๊พผ๋‹ค. let change = String(n,radix: k) 2. ๋ฐ”๊พผ ๋ฌธ์ž๋ฅผ 0์„ ๊ธฐ์ค€์œผ๋กœ ๋‚˜๋ˆˆ๋‹ค. let numbers = change.split(separator: "0") 3. ์†Œ์ˆ˜์ธ์ง€ ํŒ๋ณ„ํ•œ๋‹ค. func isPrimeNumber(_ n:Int) -> Bool { if n == 1 { return false } if n == 2 || n == 3 {.. 2022. 1. 19.
728x90
๋ฐ˜์‘ํ˜•