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

potato's devlog 437

[์•Œ๊ณ ๋ฆฌ์ฆ˜] Dynamic Programming (๋™์  ๊ณ„ํš๋ฒ•, DP) (feat. Swift ์Šค์œ„ํ”„ํŠธ)

Dynamic Programming (๋™์  ๊ณ„ํš๋ฒ•) ๋™์ ๊ณ„ํš๋ฒ•(๋‹ค์ด๋‚˜๋ฏน ํ”„๋กœ๊ทธ๋ž˜๋ฐ) ์ด๋ž€, ๋ณต์žกํ•œ ๋ฌธ์ œ๋ฅผ ๊ฐ„๋‹จํ•œ ์—ฌ๋Ÿฌ ๊ฐœ์˜ ๋ฌธ์ œ๋กœ ๋‚˜๋ˆ„์–ด ํ‘ธ๋Š” ๋ฐฉ๋ฒ•์„ ๋งํ•œ๋‹ค. ์ด๊ฒƒ์€ ๋ถ€๋ถ„ ๋ฌธ์ œ ๋ฐ˜๋ณต๊ณผ ์ตœ์  ๋ถ€๋ถ„ ๊ตฌ์กฐ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์ผ๋ฐ˜์ ์ธ ๋ฐฉ๋ฒ•์— ๋น„ํ•ด ๋”์šฑ ์ ์€ ์‹œ๊ฐ„์„ ๋‚ด์–ด ํ’€ ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค. - Wikipedia โ–ท ์ฝ”๋”ฉํ…Œ์ŠคํŠธ์—์„œ์˜ DP ์ฝ”๋”ฉํ…Œ์ŠคํŠธ์˜ ๋‹จ๊ณจ ๋ฌธ์ œ๋กœ ์ถœ์ œ๋˜๊ณ  ์žˆ๊ธฐ์— ํ•„์ˆ˜์ ์œผ๋กœ ์•Œ์•„์•ผํ•˜๋Š” ๊ฐœ๋… ์ค‘ ํ•˜๋‚˜์ด๋‹ค. ๊ฐ„ํ˜น ์ œ์•ฝ์‚ฌํ•ญ์— ์ฃผ์–ด์ง€๋Š” ์ˆซ์ž์˜ ๋ฒ”์œ„๊ฐ€ ํฌ๊ณ , ๊ฒฝ์šฐ์˜ ์ˆ˜๊ฐ€ ์—„์ฒญ ๋งŽ์€ ๋ฌธ์ œ๋“ค์ด ๋Œ€๋ถ€๋ถ„ DP(๋™์ ๊ณ„ํš๋ฒ•) ์„ ํ™œ์šฉํ•˜์—ฌ ํ’€์–ด์•ผ ํ•˜๋Š” ๋ฌธ์ œ์ด๋‹ค. Dynamic Programming (๋™์  ๊ณ„ํš๋ฒ•) ๋ฐฉ๋ฒ• ๋ชจ๋“  ์ž‘์€ ๋ฌธ์ œ๋“ค์„ ํ•œ ๋ฒˆ๋งŒ ํ’€์–ด์•ผ ํ•œ๋‹ค. ๋”ฐ๋ผ์„œ ์ •๋‹ต์„ ๊ตฌํ•œ ์ž‘์€ ๋ฌธ์ œ์˜ ๋‹ต์€ ์–ด๋”˜๊ฐ€์— ๋ฉ”๋ชจํ•ด๋†“๋Š”..

Algorithm/Basic 2022.03.03

[Swift] ๊ณต์‹ ๋ฌธ์„œ ์ •๋ฆฌ (15) - Deinitialization (์†Œ๋ฉธ์ž, ๋””์ด๋‹ˆ์…œ๋ผ์ด์ €, deinit)

์•ˆ๋…•ํ•˜์„ธ์š”, ๊ฐ์ž์ž…๋‹ˆ๋‹ค. ์ง€๋‚œ๋ฒˆ 4์ผ๊ฐ„ ๊ณต๋ถ€ํ–ˆ๋˜ ์ƒ์„ฑ์ž์— ์ด์–ด์„œ ์†Œ๋ฉธ์ž์— ๋Œ€ํ•ด์„œ ๊ณต๋ถ€ํ•œ ๋‚ด์šฉ์„ ์˜ฌ๋ ค๋ด…๋‹ˆ๋‹ค. ๊ณต์‹๋ฌธ์„œ.. ๊ธธ์–ด์„œ ์–ด๋ ค์›Œใ…“์–ด์–ด์–ด Swift Document chap.15 Deinitialization ๋ฐ”๋กœ๊ฐ€๊ธฐ Deinitialization — The Swift Programming Language (Swift 5.6) Deinitialization A deinitializer is called immediately before a class instance is deallocated. You write deinitializers with the deinit keyword, similar to how initializers are written with the init keyword. Dein..

[Swift] ๊ณต์‹ ๋ฌธ์„œ ์ •๋ฆฌ (14) - Initailization (์ƒ์„ฑ์ž, ์ดˆ๊ธฐ์ž, init์ด๋ž€?)

์•ˆ๋…•ํ•˜์„ธ์š”, ๊ฐ์ž์ž…๋‹ˆ๋‹ค. Swift ์Šคํ„ฐ๋””๋ฅผ ์ง„ํ–‰ํ•˜๋ฉด์„œ 4์ผ๊ฐ„ ๊ณต๋ถ€ํ–ˆ๋˜.. ์ƒ์„ฑ์ž ์ฑ•ํ„ฐ๋ฅผ ์—…๋กœ๋“œํ•ด๋ณผ๊ฒŒ์š”. ์ •๋ง ๊ธธ๊ณ  ๊ธธ์–ด์„œ ์ง€๋ฃจํ–ˆ์–ด์š”.. ๊ทผ๋ฐ๋„ ์™„์ „ํ•œ ์ดํ•ด๋Š” ์•„์ง ๋ชปํ–ˆ๋‹ค๋Š” ๊ฒƒ์ด ํ•จ์ •!! ๋น ๋ฅด๊ฒŒ ํ›‘๊ณ  ์ง€๋‚˜๊ฐ€๋Š”๊ฒŒ ๋ชฉํ‘œ์˜€์–ด์„œ ์™„์ „ํ•œ ์ดํ•ด๋Š” ํž˜๋“ค์—ˆ์ง€๋งŒ, ์•„ ์ƒ์„ฑ์ž๋Š” ์ด๋Ÿด๋•Œ ์‚ฌ์šฉํ•˜๋Š”๊ตฌ๋‚˜ ์ด๋Ÿด๋•Œ ์•ˆ๋˜๋Š”๊ตฌ๋‚˜! ์ด๋Ÿฐ ๊ธฐ๋ณธ์ ์ธ ๊ฐœ๋…์„ ๋‹ค์ง€๋Š” ์‹œ๊ฐ„์ด์—ˆ์–ด์š”. ์•ž์œผ๋กœ ์ƒ์„ฑ์ž์—๋Œ€ํ•ด์„œ ๋‹ค์‹œํ•œ๋ฒˆ ์ •๋…ํ•˜๋ฉด์„œ ๊ถ๊ธˆํ•œ ์ ์— ๋Œ€ํ•ด์„œ ํฌ์ŠคํŒ…ํ•˜๋„๋ก ํ•ด์•ผ๊ฒ ์–ด์š”. Swift Document chap.14 initialization ๋ฐ”๋กœ๊ฐ€๊ธฐ Initialization — The Swift Programming Language (Swift 5.6) Initialization Initialization is the process of prepari..

[๋ฐฑ์ค€] (Swift ์Šค์œ„ํ”„ํŠธ) 17103๋ฒˆ - ๊ณจ๋“œ๋ฐ”ํ ํŒŒํ‹ฐ์…˜

๋ฌธ์ œ ๋งํฌ https://www.acmicpc.net/problem/17103 17103๋ฒˆ: ๊ณจ๋“œ๋ฐ”ํ ํŒŒํ‹ฐ์…˜ ์ฒซ์งธ ์ค„์— ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค์˜ ๊ฐœ์ˆ˜ T (1 ≤ T ≤ 100)๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ๊ฐ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋Š” ํ•œ ์ค„๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๊ณ , ์ •์ˆ˜ N์€ ์ง์ˆ˜์ด๊ณ , 2 < N ≤ 1,000,000์„ ๋งŒ์กฑํ•œ๋‹ค. www.acmicpc.net ๋ฌธ์ œ ํ•ด๊ฒฐ ์•„์ด๋””์–ด ํ•จ์ˆ˜ isPrimeNumber ํ˜„์žฌ ์ž…๋ ฅ๋ฐ›์€ ์ˆ˜๊นŒ์ง€ ๋ฌด์Šจ ์†Œ์ˆ˜๊ฐ€ ์กด์žฌํ•˜๋Š”์ง€ ๋ฐฐ์—ด๋กœ ์ •๋ฆฌ ์˜ˆ๋ฅผ๋“ค์–ด 9๊ฐ€ ์ž…๋ ฅ๋˜๋ฉด, [2, 3, 5, 7] ์ด ๋ฐ˜ํ™˜๋œ๋‹ค. main ์ž…๋ ฅ๋ฐ›์€ num ๊นŒ์ง€ ๋ฌด์Šจ ์†Œ์ˆ˜๊ฐ€ ์กด์žฌํ•˜๋Š”์ง€ isPrimeNums ๋ฐฐ์—ด ์ƒ์„ฑ 2๋ถ€ํ„ฐ num/2 ๊นŒ์ง€ ๋ฐ˜๋ณต ์™œ num/2 ๋ƒ? 10์„ ์˜ˆ๋กœ ๋“ค๋ฉด, (3, 7), (5, 5) (7, 3) ์ด๋ ‡๊ฒŒ ๊ณจ๋“œ๋ฐ”ํ ํŒŒํ‹ฐ์…˜์ด 3..

Algorithm/Baekjoon 2022.03.01

[Swift] ๊ณต์‹ ๋ฌธ์„œ ์ •๋ฆฌ (13) - Inheritance (์ƒ์†) (Override, final, super, ์žฌ์ •์˜, ์˜ค๋ฒ„๋ผ์ด๋“œ ๋ž€?)

์•ˆ๋…•ํ•˜์„ธ์š”, ๊ฐ์ž์ž…๋‹ˆ๋‹ค. ์˜ค๋Š˜์€ ์Šค์œ„ํ”„ํŠธ ์ƒ์†(Inheritance)์— ๋Œ€ํ•ด์„œ ๊ณต๋ถ€ํ–ˆ์Šต๋‹ˆ๋‹ค. ์˜ค๋ฒ„๋ผ์ด๋“œ ๋ผ๊ณ  ์ •๋ง ์ค‘์š”ํ•œ ๊ฐœ๋… ์ค‘ ํ•˜๋‚˜์ธ๋ฐ์š”, ์ƒ๊ฐ๋ณด๋‹ค ๊ฐœ๋…์€ ๊ฐ„๋‹จํ•ฉ๋‹ˆ๋‹ค. Swift Document chap.13 Inheritance ๋ฐ”๋กœ๊ฐ€๊ธฐ Inheritance (์ƒ์†) ํด๋ž˜์Šค๋Š” ๋‹ค๋ฅธ ํด๋ž˜์Šค๋กœ๋ถ€ํ„ฐ ์ƒ์† ํ• (๋ฐ›์„) ์ˆ˜ ์žˆ๋‹ค. ์ด๊ฒƒ์ด ํด๋ž˜์Šค๊ฐ€ ๋‹ค๋ฅธ ํƒ€์ž…๋“ค๊ณผ ๊ตฌ๋ถ„๋˜๋Š” ๊ทผ๋ณธ์ ์ธ ์š”์†Œ์ด๋‹ค. ๋‹จ, ํ•˜๋‚˜์˜ ํด๋ž˜์Šค๋งŒ ์ƒ์† ํ•  (๋ฐ›์„)์ˆ˜ ์žˆ๋‹ค. Swift ํด๋ž˜์Šค๋Š” ์Šˆํผํด๋ž˜์Šค์— ์†ํ•œ ๋ฉ”์„œ๋“œ, ํ”„๋กœํผํ‹ฐ ๋ฐ ํ•˜์œ„ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ํ˜ธ์ถœํ•˜๊ณ  ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ํ•ด๋‹น ๋ฉ”์„œ๋“œ, ํ”„๋กœํผํ‹ฐ ๋ฐ ์Šคํฌ๋ฆฝํŠธ์˜ overrideํ•œ ๋ฒ„์ „์„ ์ œ๊ณตํ•˜์—ฌ ํ•ด๋‹น ๋™์ž‘์„ ์ˆ˜์ •ํ•˜๊ฑฐ๋‚˜ ๋ฏธ์„ธ ์กฐ์ •ํ•  ์ˆ˜ ์žˆ๋‹ค. Swift๋Š” override์ •์˜์— ์ผ์น˜ํ•˜๋Š” ์Šˆํผํด๋ž˜์Šค ์ •..

[๋ฐฑ์ค€] (Swift) 11653๋ฒˆ - ์†Œ์ธ์ˆ˜๋ถ„ํ•ด

๋ฌธ์ œ ๋งํฌ https://www.acmicpc.net/problem/11653 11653๋ฒˆ: ์†Œ์ธ์ˆ˜๋ถ„ํ•ด ์ฒซ์งธ ์ค„์— ์ •์ˆ˜ N (1 ≤ N ≤ 10,000,000)์ด ์ฃผ์–ด์ง„๋‹ค. www.acmicpc.net ๋‚ด๊ฐ€ ํ‘ผ ํ’€์ด 2๋ถ€ํ„ฐ ์ฐจ๊ทผ์ฐจ๊ทผ ๋‚˜๋ˆ ์ฃผ๋ฉด์„œ print ํ•ด์คŒ ๋ฒ”์œ„๋Š” ์ˆซ์ž num๊นŒ์ง€๋กœ ์„ค์ •ํ–ˆ์Œ ๋งˆ์ง€๋ง‰์— 1์ด ์•„๋‹Œ๊ฒฝ์šฐ ์†Œ์ˆ˜๋กœ ๋งˆ๋ฌด๋ฆฌ ์ง€์–ด์กŒ๋‹ค๋Š” ๋œป์ด๋ฏ€๋กœ, ๋งˆ์ง€๋ง‰ ์†Œ์ˆ˜๋„ ์ถœ๋ ฅํ•ด์คŒ. ๊ตณ์ด ์ •๋ ฌ์€ ํ•„์š”์—†์Œ. 2๋ถ€ํ„ฐ ์‹œ์ž‘ํ•ด์„œ ๊ฐ€์žฅ ์ž‘์€ ์†Œ์ˆ˜๋ถ€ํ„ฐ ์ถœ๋ ฅ๋˜๊ฒŒ ๋จ import Foundation var num = Int(readLine()!)! let n = Int(sqrt(Double(num))) for i in stride(from: 2, to: num, by: 1) { while num % i == 0 { num /=..

Algorithm/Baekjoon 2022.02.28

[๋ฐฑ์ค€] (Swift) 2089๋ฒˆ - -2์ง„๋ฒ•

๋ฌธ์ œ ๋งํฌ https://www.acmicpc.net/problem/2089 ๋‚ด๊ฐ€ ํ‘ผ ํ’€์ด - ๋งž์•˜์Šต๋‹ˆ๋‹ค! ๋ณต์žกํ•˜๊ฒŒ ์ƒ๊ฐํ•˜์ง€ ์•Š๊ณ  if๋ฌธ์œผ๋กœ ์ƒํ™ฉ์„ ๋‚˜๋ˆ„์–ด์„œ ๋ฌธ์ œ๋ฅผ ํ’€์—ˆ๋‹ค. ์กฐ๊ธˆ ๋” ํšจ์œจ์ ์ธ ์ฝ”๋”ฉ ๋ฐฉ๋ฒ•์„ ์ฐพ์•„๋ด์•ผ๊ฒ ๋‹ค. var num = Int(readLine()!)! var ans = "" while true { if num == -1 { ans += "11" break } else if num == 0 { ans += "0" break } else if num == 1{ ans += "1" break } if num 0 ..

Algorithm/Baekjoon 2022.02.26

[Swift] ๊ณต์‹ ๋ฌธ์„œ ์ •๋ฆฌ (12) - Subscripts (์„œ๋ธŒ ์Šคํฌ๋ฆฝํŠธ, [])

์•ˆ๋…•ํ•˜์„ธ์š”, ๊ฐ์ž์ž…๋‹ˆ๋‹ค. ์˜ค๋Š˜์€ ์„œ๋ธŒ์Šคํฌ๋ฆฝํŠธ์— ๋Œ€ํ•ด์„œ ๊ณต๋ถ€ํ•ด๋ณด์•˜์Šต๋‹ˆ๋‹ค. ์ฝ”๋“œ๋ฅผ ์‚ดํŽด๋ณด๋ฉด, string์—์„œ ์ธ๋ฑ์Šค๋กœ ์ ‘๊ทผํ•˜๋Š” ๋ฐฉ์‹์— ๋Œ€ํ•ด์„œ๋„ ๋‚˜์˜ค๋Š”๋ฐ์š”, ์ด ๋ถ€๋ถ„์— ๋Œ€ํ•ด์„œ๋„ ํŒŒ์ด์ฌ์—์„œ๋Š” ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ๋˜๋Š”๋ฐ, ์™œ ์•ˆ๋ผ!!! ํ•˜๋ฉด์„œ ์„ฑ์งˆ๋ƒˆ๋˜ ๊ธฐ์–ต์ด ์žˆ๋„ค์š” ํ—ˆํ—ˆ... ์„œ๋ธŒ์Šคํฌ๋ฆฝํŠธ๋ฅผ ํ™œ์šฉํ•˜๋ฉด ๋ฌธ์ž์—ด์—์„œ๋„ [index]๋ฅผ ํ™œ์šฉํ•˜์—ฌ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ์‚ฌ์‹ค! ๊ทธ๋Ÿผ ์ด์ œ ์‚ดํŽด๋ณด๋„๋ก ํ•˜์ฃ . Swift Documents chap.12 Subscripts ๋ฐ”๋กœ๊ฐ€๊ธฐ Subscripts — The Swift Programming Language (Swift 5.6) Subscripts Classes, structures, and enumerations can define subscripts, which are shortcuts f..

[Swift] ๊ณต์‹ ๋ฌธ์„œ ์ •๋ฆฌ (11) - Methods (๋ฉ”์„œ๋“œ)

์•ˆ๋…•ํ•˜์„ธ์š”, ๊ฐ์ž์ž…๋‹ˆ๋‹ค. ์˜ค๋Š˜์€ ์Šค์œ„ํ”„ํŠธ ๊ณต์‹๋ฌธ์„œ 11์ฑ•ํ„ฐ์ธ, ๋ฉ”์„œ๋“œ์— ๋Œ€ํ•ด์„œ ์ •๋ฆฌํ•ด๋ดค์Šต๋‹ˆ๋‹ค. ์Šค์œ„ํ”„ํŠธ ์Šคํ„ฐ๋””๋ฅผ ํ•˜๋ฉด์„œ ๋‚˜๋ฆ„ ๋งค์ผ๋งค์ผ ๊พธ์ค€ํžˆ ์ •๋ฆฌ์ค‘์ธ๋ฐ์š”, ํ™•์‹คํžˆ ์Šคํ„ฐ๋””๋ฅผ ์šด์˜ํ•˜๋ฉฐ ์‚ฌ๋žŒ๋“ค๊ณผ ํ•จ๊ป˜ ๊ณต๋ถ€ํ•˜๋Š” ๊ฒƒ์ด ํšจ์œจ์ด ์˜ค๋ฅด๋Š” ๊ฒƒ๊ฐ™์•„์š”. ์–ผ๋ฅธ ๊ธฐ์ดˆ๊ณต๋ถ€๋ฅผ ๋๋‚ด๊ณ  ํ† ์ด ํ”„๋กœ์ ํŠธ๋„ ํ•จ๊ป˜ ํ•ด๋ณด๊ณ ์‹ถ์€ ๋งˆ์Œ์ด๋„ค์š”! ๊ทธ๋Ÿผ ์‹œ์ž‘ Swift Documents chap.11 Methods ๋ฐ”๋กœ๊ฐ€๊ธฐ Methods — The Swift Programming Language (Swift 5.6) Methods Methods are functions that are associated with a particular type. Classes, structures, and enumerations can all define instan..

[Swift] ๊ณต์‹ ๋ฌธ์„œ ์ •๋ฆฌ (10) - Properties (์ €์žฅ ํ”„๋กœํผํ‹ฐ, ๊ณ„์‚ฐ ํ”„๋กœํผํ‹ฐ, ํƒ€์ž… ํ”„๋กœํผํ‹ฐ, ์˜ต์ €๋ฒ„, wrapper)

์•ˆ๋…•ํ•˜์„ธ์š”, ๊ฐ์ž์ž…๋‹ˆ๋‹ค. ์˜ค๋Š˜์€ property์— ๋Œ€ํ•ด์„œ ๊ณต๋ถ€ํ•ด๋ณด์•˜์Šต๋‹ˆ๋‹ค. ํ”„๋กœํผํ‹ฐ ๊ฐœ๋…์„ ๊ณต๋ถ€ํ•˜๋ฉด์„œ ์ฐธ ๋ชจํ˜ธํ•˜๊ณ  ์ดํ•ด๊ฐ€ ๊ฐ€์ง€ ์•Š์•˜๋˜ ๋ถ€๋ถ„์ด ๋งŽ์•˜๋Š”๋ฐ์š”, ์ด๋Ÿฐ ๋ถ€๋ถ„์— ๋Œ€ํ•ด์„œ๋Š” ์ถ”ํ›„์— ํ”„๋กœํผํ‹ฐ ์ •๋ณตํ•˜๊ธฐ ํฌ์ŠคํŒ…์„ ๋‹ค์‹œ ํ•œ ๋ฒˆ ํ•ด์•ผํ•  ๊ฒƒ ๊ฐ™์•„์š”. ์ผ๋‹จ ๊ธฐ์ดˆ๊ฐœ๋…์„ ์žก์€ ์ •๋ฆฌ๊ธ€ ์ •๋„๋กœ ๋ด์ฃผ์„ธ์š”! ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค. Swift Document chap.10 Properties ๋ฐ”๋กœ๊ฐ€๊ธฐ Properties — The Swift Programming Language (Swift 5.6) Properties Properties associate values with a particular class, structure, or enumeration. Stored properties store constant and variabl..

๋ฐ˜์‘ํ˜•