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

Algorithm 237

[๋ฐฑ์ค€] (Swift) 17087๋ฒˆ - ์ˆจ๋ฐ”๊ผญ์งˆ6 (๋ฌธ์ œ ํ’€์ด ์„ค๋ช…, GCD์•Œ๊ณ ๋ฆฌ์ฆ˜_์Šค์œ„ํ”„ํŠธ)

๋ฌธ์ œ ๋งํฌ https://www.acmicpc.net/problem/17087 17087๋ฒˆ: ์ˆจ๋ฐ”๊ผญ์งˆ 6 ์ˆ˜๋นˆ์ด๋Š” ๋™์ƒ N๋ช…๊ณผ ์ˆจ๋ฐ”๊ผญ์งˆ์„ ํ•˜๊ณ  ์žˆ๋‹ค. ์ˆ˜๋นˆ์ด๋Š” ํ˜„์žฌ ์  S์— ์žˆ๊ณ , ๋™์ƒ์€ A1, A2, ..., AN์— ์žˆ๋‹ค. ์ˆ˜๋นˆ์ด๋Š” ๊ฑธ์–ด์„œ ์ด๋™์„ ํ•  ์ˆ˜ ์žˆ๋‹ค. ์ˆ˜๋นˆ์ด์˜ ์œ„์น˜๊ฐ€ X์ผ๋•Œ ๊ฑท๋Š”๋‹ค๋ฉด 1์ดˆ ํ›„์— X+D๋‚˜ X-D๋กœ ์ด www.acmicpc.net ๋ฌธ์ œ๊ฐ€ ์กฐ๊ธˆ ์• ๋งคํ•˜๋‹ค. ๋„ํ†ต input๊ณผ output์˜ ๊ด€๊ณ„๊ฐ€ ์ดํ•ด๊ฐ€ ๊ฐ€์งˆ ์•Š์•„์„œ ๋ฌธ์ œ๋ฅผ ์ดํ•ดํ•˜๊ธฐ ์œ„ํ•ด ์ธํ„ฐ๋„ท์„ ์ฐพ์•„๋ณด์•˜๋‹ค. ๊ทธ๋ ‡๊ฒŒ ์•Œ์•„๋‚ธ ์‚ฌ์‹ค์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค. ์ตœ๋Œ€๊ณต์•ฝ์ˆ˜๋ฅผ ๊ตฌํ•˜๋Š” ๋ฌธ์ œ์ด๋‹ค. ๊ทธ ์ค‘์—์„œ๋„, GCD ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ํ™œ์šฉํ•˜์—ฌ ํ‘ธ๋Š” ๋ฌธ์ œ์ด๋‹ค. GCD์•Œ๊ณ ๋ฆฌ์ฆ˜ (์œ ํด๋ฆฌ๋“œ ํ˜ธ์ œ๋ฒ•)์„ ์ดํ•ดํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ์ด๊ธ€ ์„ ์ฐธ๊ณ ํ–ˆ๋‹ค. โ–ถ ๊ทผ๋ฐ ๋„๋Œ€์ฒด ์™œ, ์ตœ๋Œ€๊ณต์•ฝ์ˆ˜๊ฐ€ ..

Algorithm/Baekjoon 2022.02.19

[๋ฐฑ์ค€] (Swift) 11656๋ฒˆ - ์ ‘๋ฏธ์‚ฌ ๋ฐฐ์—ด

๋ฌธ์ œ ๋งํฌ https://www.acmicpc.net/problem/11656 11656๋ฒˆ: ์ ‘๋ฏธ์‚ฌ ๋ฐฐ์—ด ์ฒซ์งธ ์ค„์— ๋ฌธ์ž์—ด S๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. S๋Š” ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ๊ณ , ๊ธธ์ด๋Š” 1,000๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™๋‹ค. www.acmicpc.net ๋‚ด๊ฐ€ ํ‘ผ ํ’€์ด for๋ฌธ์„ ํ™œ์šฉํ•˜์—ฌ ํ•œ๊ธ€์ž์”ฉ ๋นผ๊ณ  stringํ˜•ํƒœ์ธ word ๋ณ€์ˆ˜์— ๋„ฃ์–ด์ค€๋‹ค. abc -> bc -> c word ๋ณ€์ˆ˜ ์ „๋ถ€๋ฅผ answer ๋ฐฐ์—ด์— push answer ๋ฐฐ์—ด์„ sorted() ๋ฉ”์„œ๋“œ๋ฅผ ํ™œ์šฉํ•˜์—ฌ ์ •๋ ฌ for ๋ฌธ์„ ํ™œ์šฉํ•˜์—ฌ print let line = Array(readLine()!) var answer: [String] = [] for i in 0..

Algorithm/Baekjoon 2022.02.19

[๋ฐฑ์ค€] (Swift) 10824๋ฒˆ - ๋„ค ์ˆ˜

๋ฌธ์ œ ๋งํฌ https://www.acmicpc.net/problem/10824 10824๋ฒˆ: ๋„ค ์ˆ˜ ์ฒซ์งธ ์ค„์— ๋„ค ์ž์—ฐ์ˆ˜ A, B, C, D๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. (1 ≤ A, B, C, D ≤ 1,000,000) www.acmicpc.net ๋‚ด๊ฐ€ ํ‘ผ ํ’€์ด ์–ด์ฐจํ”ผ ๋ฌธ์ œ์—์„œ 4๊ฐœ์˜ ์ˆ˜ ๋งŒ ์ฃผ์–ด์งˆ ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์— ์ธ๋ฑ์Šค๋กœ 0,1 ๋ฒˆ์ด๋ฉด answer1์— ์ €์žฅ ์ธ๋ฑ์Šค 2,3 ์ด๋ฉด answer2์— ์ €์žฅ answer1, answer2 ๋Š” ์•ž+๋’ค ๋ฌธ์ž๊ฐ€ ํ•ฉ์ณ์ ธ์•ผํ•˜๊ธฐ ๋•Œ๋ฌธ์— String์œผ๋กœ ์ฒ˜๋ฆฌ printํ• ๋•Œ int๋กœ ๋ฐ”๊ฟ”์„œ ์ถœ๋ ฅ let line = readLine()!.split(separator: " ").map{ String($0) } var answer1 = "" var answer2 = "" for i in 0..

Algorithm/Baekjoon 2022.02.18

[๋ฐฑ์ค€] (Swift) 11655๋ฒˆ - ROT13

๋ฌธ์ œ ๋งํฌ https://www.acmicpc.net/problem/11655 11655๋ฒˆ: ROT13 ์ฒซ์งธ ์ค„์— ์•ŒํŒŒ๋ฒณ ๋Œ€๋ฌธ์ž, ์†Œ๋ฌธ์ž, ๊ณต๋ฐฑ, ์ˆซ์ž๋กœ๋งŒ ์ด๋ฃจ์–ด์ง„ ๋ฌธ์ž์—ด S๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. S์˜ ๊ธธ์ด๋Š” 100์„ ๋„˜์ง€ ์•Š๋Š”๋‹ค. www.acmicpc.net ๋‚ด๊ฐ€ ํ‘ผ ํ’€์ด (1) - ๋Ÿฐํƒ€์ž„ ์—๋Ÿฌ ๋ฐฐ์—ด ๋‘๊ฐœ๋ฅผ ์‚ฌ์šฉํ•ด์„œ 26๋ฌธ์ž 26๋ฌธ์ž๋ฅผ ๋„ฃ์„๊นŒ ํ•˜๋‹ค๊ฐ€ dic์ด ๋ฉ”๋ชจ๋ฆฌ๊ฐ€ ๋” ์ ์€๊ฒƒ(?)์„ ์•Œ๊ณ  dic์œผ๋กœ ๊ตฌ์„ฑํ–ˆ๋‹ค. ์•„๋ฌด๋ž˜๋„ ๋ชจ๋“  ๋ฌธ์ž๋ฅผ dic์— ๋„ฃ๋Š” ๊ฒƒ์ด๋‹ค ๋ณด๋‹ˆ, ๋Ÿฐํƒ€์ž„์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜๋Š” ๊ฒƒ ๊ฐ™๋‹ค. let line = Array(readLine()!) var answer: [Character] = [] let dic: [String:Character] = ["a":"n", "b":"o", "c":"p", "d":"q"..

Algorithm/Baekjoon 2022.02.17

[๋ฐฑ์ค€] (Swift) 10820๋ฒˆ - ๋ฌธ์ž์—ด ๋ถ„์„

๋ฌธ์ œ ๋งํฌ https://www.acmicpc.net/problem/10820 10820๋ฒˆ: ๋ฌธ์ž์—ด ๋ถ„์„ ๋ฌธ์ž์—ด N๊ฐœ๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์ด๋•Œ, ๋ฌธ์ž์—ด์— ํฌํ•จ๋˜์–ด ์žˆ๋Š” ์†Œ๋ฌธ์ž, ๋Œ€๋ฌธ์ž, ์ˆซ์ž, ๊ณต๋ฐฑ์˜ ๊ฐœ์ˆ˜๋ฅผ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ๊ฐ ๋ฌธ์ž์—ด์€ ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž, ๋Œ€๋ฌธ์ž, ์ˆซ์ž, ๊ณต๋ฐฑ์œผ๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ www.acmicpc.net ๋‚ด๊ฐ€ ํ‘ผ ํ’€์ด ์ž…๋ ฅ๋ฐ›์€ character๋ฅผ ๋ชจ๋‘ ํ•œ ๋ฌธ์ž์”ฉ ๋œฏ์–ด์„œ ๋ฐฐ์—ด๋กœ ์ €์žฅํ•ด์ค€ ๋‹ค์Œ, if ๋ฌธ์„ ํ™œ์šฉํ•ด์„œ count while let input = readLine() { var str = Array(input) var lower = 0 var upper = 0 var num = 0 var space = 0 for i in str { if i >= "a" && i = "A" && i

Algorithm/Baekjoon 2022.02.16

[๋ฐฑ์ค€] (Swift) 2743๋ฒˆ - ๋‹จ์–ด ๊ธธ์ด ์ œ๊ธฐ

๋ฌธ์ œ ๋งํฌ https://www.acmicpc.net/problem/2743 2743๋ฒˆ: ๋‹จ์–ด ๊ธธ์ด ์žฌ๊ธฐ ์•ŒํŒŒ๋ฒณ์œผ๋กœ๋งŒ ์ด๋ฃจ์–ด์ง„ ๋‹จ์–ด๋ฅผ ์ž…๋ ฅ๋ฐ›์•„, ๊ทธ ๊ธธ์ด๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. www.acmicpc.net ๋‚ด๊ฐ€ ํ‘ผ ํ’€์ด ํ’€์ด๋ผ๊ณ  ํ•˜๊ธฐ๋„ ๋ฏผ๋งํ•˜๋‹ค.. ํฌ์ŠคํŒ…ํ• ๊นŒ๋ง๊นŒ ๊ณ ๋ฏผํ–ˆ๋˜ ๋ฏผ๋งํ•œ ๋ฌธ์ œ ^///^ ๊ทธ๋ž˜๋„ 1์ผ1๋ฐฑ์ค€์˜ ํ•œ ๋ฌธ์ œ๋‹ˆ๊นŒ.. ใ…Žใ…Ž let line = readLine()! print(line.count)

Algorithm/Baekjoon 2022.02.16

[๋ฐฑ์ค€] (Swift) 10809๋ฒˆ - ์•ŒํŒŒ๋ฒณ ์ฐพ๊ธฐ

๋ฌธ์ œ ๋งํฌ https://www.acmicpc.net/problem/10809 10809๋ฒˆ: ์•ŒํŒŒ๋ฒณ ์ฐพ๊ธฐ ๊ฐ๊ฐ์˜ ์•ŒํŒŒ๋ฒณ์— ๋Œ€ํ•ด์„œ, a๊ฐ€ ์ฒ˜์Œ ๋“ฑ์žฅํ•˜๋Š” ์œ„์น˜, b๊ฐ€ ์ฒ˜์Œ ๋“ฑ์žฅํ•˜๋Š” ์œ„์น˜, ... z๊ฐ€ ์ฒ˜์Œ ๋“ฑ์žฅํ•˜๋Š” ์œ„์น˜๋ฅผ ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„ํ•ด์„œ ์ถœ๋ ฅํ•œ๋‹ค. ๋งŒ์•ฝ, ์–ด๋–ค ์•ŒํŒŒ๋ฒณ์ด ๋‹จ์–ด์— ํฌํ•จ๋˜์–ด ์žˆ์ง€ ์•Š๋‹ค๋ฉด -1์„ ์ถœ www.acmicpc.net ๋‚ด๊ฐ€ ํ‘ผ ํ’€์ด ์ž…๋ ฅ๋ฐ›์„ ๋ฌธ์ž๋ฐฐ์—ด line / ๊ฒ€์‚ฌ๊ฐ€ ์™„๋ฃŒ๋œ ๊ธ€์ž๋ฅผ ๋„ฃ์–ด์ฃผ๋Š” char ๋ฐฐ์—ด left / ์ •๋‹ต๋ฐฐ์—ด answer ์ •๋‹ต ๋ฐฐ์—ด์—๋Š”, ๋“ฑ์žฅํ•˜์ง€ ์•Š์€ ๋ฌธ์ž๋Š” -1 ์ด ๋“ค์–ด๊ฐ€์•ผํ•˜๊ธฐ ๋•Œ๋ฌธ์—, ์šฐ์„  -1์„ 26๊ฐœ ์ฑ„์› ๋‹ค. (a...z๋Š” 26๊ฐœ) ๋‚˜๋Š” line์—์„œ ํ•œ๊ธ€์ž์”ฉ for in ๊ตฌ๋ฌธ์œผ๋กœ ๋”ฐ์™€์„œ, ํ•ด๋‹น char์˜ asciiValue๋ฅผ ํ™œ์šฉํ•˜์—ฌ ๋ช‡๋ฒˆ์งธ ์•ŒํŒŒ๋ฒณ์ธ์ง€ answer..

Algorithm/Baekjoon 2022.02.15

[๋ฐฑ์ค€] (Swift) 10808๋ฒˆ - ์•ŒํŒŒ๋ฒณ ๊ฐœ์ˆ˜

๋ฌธ์ œ ๋งํฌ https://www.acmicpc.net/problem/10808 10808๋ฒˆ: ์•ŒํŒŒ๋ฒณ ๊ฐœ์ˆ˜ ๋‹จ์–ด์— ํฌํ•จ๋˜์–ด ์žˆ๋Š” a์˜ ๊ฐœ์ˆ˜, b์˜ ๊ฐœ์ˆ˜, …, z์˜ ๊ฐœ์ˆ˜๋ฅผ ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„ํ•ด์„œ ์ถœ๋ ฅํ•œ๋‹ค. www.acmicpc.net ๋‚ด๊ฐ€ ํ‘ผ ํ’€์ด 0๋ฐฐ์—ด์„ ๋งŒ๋“ค์–ด์ฃผ๊ณ , ์ž…๋ ฅ๋ฐ›๋Š” ์•ŒํŒŒ๋ฒณ์„ ์•„์Šคํ‚ค์ฝ”๋“œ 10์ง„์ˆ˜๋กœ ๋ณ€ํ™˜ํ•œ๋’ค ํ•ด๋‹นํ•˜๋Š” ์ธ๋ฑ์Šค์œ„์น˜์˜ ์ˆ˜์— +1 ์”ฉ ํ•ด์ฃผ์—ˆ๋‹ค. ๊ธฐ์–ตํ•˜์ž, asciiValue ๋Œ€๋ฌธ์ž A๋Š” 65, ์†Œ๋ฌธ์ž a ๋Š” 97!! ์ƒ๊ฐ๋ณด๋‹ค ๋ฌธ์ž์—ด ํ•  ๋•Œ ์“ธ๋ชจ๊ฐ€ ์žˆ๋‹ค. import Foundation var array = [Int](repeating: 0, count: 26) let line = readLine()! for ch in line { array[Int(ch.asciiValue!)-97] += 1 ..

Algorithm/Baekjoon 2022.02.13

[๋ฐฑ์ค€] (Swift) 1918๋ฒˆ - ํ›„์œ„ํ‘œ๊ธฐ์‹

๋ฌธ์ œ ๋งํฌ https://www.acmicpc.net/problem/1918 1918๋ฒˆ: ํ›„์œ„ ํ‘œ๊ธฐ์‹ ์ฒซ์งธ ์ค„์— ์ค‘์œ„ ํ‘œ๊ธฐ์‹์ด ์ฃผ์–ด์ง„๋‹ค. ๋‹จ ์ด ์ˆ˜์‹์˜ ํ”ผ์—ฐ์‚ฐ์ž๋Š” ์•ŒํŒŒ๋ฒณ ๋Œ€๋ฌธ์ž๋กœ ์ด๋ฃจ์–ด์ง€๋ฉฐ ์ˆ˜์‹์—์„œ ํ•œ ๋ฒˆ์”ฉ๋งŒ ๋“ฑ์žฅํ•œ๋‹ค. ๊ทธ๋ฆฌ๊ณ  -A+B์™€ ๊ฐ™์ด -๊ฐ€ ๊ฐ€์žฅ ์•ž์— ์˜ค๊ฑฐ๋‚˜ AB์™€ ๊ฐ™์ด *๊ฐ€ ์ƒ๋žต๋˜๋Š” ๋“ฑ์˜ www.acmicpc.net ํ›„์œ„ ํ‘œ๊ธฐ์‹, ๋‚˜์—๊ฒ ๋‚ฏ์„ค์—ˆ์ง€๋งŒ, ์ •ํ˜•ํ™”๋œ ํ’€์ด๋ฐฉ๋ฒ•์ด ์žˆ๋‹ค๊ณ  ํ•œ๋‹ค. ํ›„์œ„ํ‘œ๊ธฐ์‹๊ณผ ๋น„์Šทํ•œ ๋ชจ๋“ ๋ฌธ์ œ๋Š” ๋Œ€๋ถ€๋ถ„ stack์„ ์ด์šฉํ•ด์„œ ํ‘ผ๋‹ค๊ณ ํ•œ๋‹ค. ์ž˜ ์ตํ˜€๋‘์ž. ๋‚ด๊ฐ€ ํ‘ผ ํ’€์ด ์šฐ์„  ํ›„์œ„ํ‘œ๊ธฐ์‹์— ๋Œ€ํ•œ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ํ’€์–ด๋ณธ ์ ์ด ์—†์—ˆ๊ธฐ์— ์ธํ„ฐ๋„ท์„ ์ฐธ๊ณ ํ•˜์—ฌ ํ’€์ดํ–ˆ๋‹ค. ๊ทธ๋ž˜์„œ ์ฝ”๋“œ๊ฐ€ ๊ฑฐ์˜ ๋น„์Šทํ•˜๋‹ค (ํ—ˆํ—ˆ.. ์–ธ์ œ์ฏค ๋‚˜๋„ ์ž˜ํ•  ์ˆ˜ ์žˆ์„๊นŒ) ์ž…๋ ฅ๋ฐ›๋Š” ํ‘œ๊ธฐ์‹์„ line, ๋‹ต์•ˆ์œผ๋กœ ์ถœ๋ ฅํ•  ๋ฐฐ์—ด์„ answer..

Algorithm/Baekjoon 2022.02.13

[๋ฐฑ์ค€] (Swift) 1935๋ฒˆ - ํ›„์œ„ ํ‘œ๊ธฐ์‹2

๋ฌธ์ œ๋งํฌ https://www.acmicpc.net/problem/1935 1935๋ฒˆ: ํ›„์œ„ ํ‘œ๊ธฐ์‹2 ์ฒซ์งธ ์ค„์— ํ”ผ์—ฐ์‚ฐ์ž์˜ ๊ฐœ์ˆ˜(1 ≤ N ≤ 26) ๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๋‘˜์งธ ์ค„์—๋Š” ํ›„์œ„ ํ‘œ๊ธฐ์‹์ด ์ฃผ์–ด์ง„๋‹ค. (์—ฌ๊ธฐ์„œ ํ”ผ์—ฐ์‚ฐ์ž๋Š” A~Z์˜ ์˜๋Œ€๋ฌธ์ž์ด๋ฉฐ, A๋ถ€ํ„ฐ ์ˆœ์„œ๋Œ€๋กœ N๊ฐœ์˜ ์˜๋Œ€๋ฌธ์ž๋งŒ์ด ์‚ฌ์šฉ๋˜๋ฉฐ, ๊ธธ์ด www.acmicpc.net ํ›„์œ„ ํ‘œ๊ธฐ์‹์„ ๊ณ„์‚ฐํ•˜๋Š” ๊ฐœ๋…์— ๋Œ€ํ•ด์„œ ์ž˜ ์•Œ์ง€ ๋ชปํ•˜์—ฌ ์ธํ„ฐ๋„ท์„ ์ฐพ์•„๋ณด๊ณ , ํ›„์œ„ํ‘œ๊ธฐ์‹์ด ์–ด๋–ค ๋ฐฉ์‹์œผ๋กœ ๊ณ„์‚ฐ๋˜๋Š”์ง€ ๋จผ์ € ์‚ดํŽด๋ณด์•˜๋‹ค. ๊ธฐ๋ณธ์ ์œผ๋กœ stack ์ž๋ฃŒ๊ตฌ์กฐ๋ฅผ ํ™œ์šฉํ•œ๋‹ค๋Š” ์ ์ด ํŠน์ง•์ด์—ˆ๋‹ค. ์ปดํ“จํ„ฐ๋Š” ์šฐ๋ฆฌ๊ฐ€ ์ผ๋ฐ˜์ ์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ์ค‘์œ„ํ‘œ๊ธฐ์‹ (1+2=3) ๋ณด๋‹ค ํ›„์œ„ํ‘œ๊ธฐ์‹์ด ๋” ์ดํ•ด๊ฐ€ ์‰ฌ์šด์ง€ ์•Œ ์ˆ˜ ์žˆ๊ฒŒ ๋˜์—ˆ๋‹ค.๊ณ„์†ํ•ด์„œ ๊ฒฐ๊ด๊ฐ’์„ stack์— ์ €์žฅํ•ด์ฃผ๊ธฐ ๋•Œ๋ฌธ์ด ์•„๋‹๊นŒ. ๋‚ด๊ฐ€ ํ•ด๋‹น ๋ฌธ์ œ๋ฅผ..

Algorithm/Baekjoon 2022.02.11
๋ฐ˜์‘ํ˜•