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

Algorithm/Baekjoon 149

[๋ฐฑ์ค€] (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) 1212๋ฒˆ - 8์ง„์ˆ˜ 2์ง„์ˆ˜

๋ฌธ์ œ๋งํฌ https://www.acmicpc.net/problem/1212 1212๋ฒˆ: 8์ง„์ˆ˜ 2์ง„์ˆ˜ ์ฒซ์งธ ์ค„์— 8์ง„์ˆ˜๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์ฃผ์–ด์ง€๋Š” ์ˆ˜์˜ ๊ธธ์ด๋Š” 333,334์„ ๋„˜์ง€ ์•Š๋Š”๋‹ค. www.acmicpc.net ๋‚ด๊ฐ€ ํ‘ผ ํ’€์ด - ์‹œ๊ฐ„์ดˆ๊ณผ (์–ด๋””์„œ ์‹œ๊ฐ„๋ณต์žก๋„๋ฅผ ์ค„์—ฌ์•ผํ• ๊นŒ์š”?) ํ•ด๊ฒฐ ์™„๋ฃŒ input์œผ๋กœ ์ˆซ์ž ํ•˜๋‚˜ํ•˜๋‚˜์”ฉ ๋Š์–ด์„œ ๋ฐฐ์—ด๋กœ ์ €์žฅ ์ˆซ์ž ํ•˜๋‚˜์”ฉ 2์ง„์ˆ˜๋กœ ๊ตฌํ•˜๊ณ , reverse ํ•ด์ค„๊ฑฐ์ž„ 314 ์ด๋ฉด, 11 / 001 / 100 ์ด ๋˜์–ด์•ผํ•จ 1์„ 2์ง„์ˆ˜๋กœ ๊ตฌํ•˜๋ฉด 1์ž„. --> ์ด๋†ˆ์„ ์„ธ์ž๋ฆฌ์ˆ˜๋กœ ๋ชจ์กฐ๋ฆฌ ์ฑ„์›Œ์ฃผ๊ธฐ ์œ„ํ•ด ์•ž์— 0 ๋‘๊ฐœ๋ฅผ ๋„ฃ์–ด์ฃผ์–ด์•ผํ•จ. ์ด๋Ÿฐ ๊ณผ์ •์ด ํ•„์š”ํ•˜๋ฏ€๋กœ, if ๋ฌธ์„ ์‚ฌ์šฉํ•ด์„œ 0์„ ๋„ฃ์–ด์คŒ ๋Œ€์‹ , 3์ฒ˜๋Ÿผ ๋งจ์•ž์—์žˆ๋Š” ์ˆซ์ž์ธ ๊ฒฝ์šฐ์—๋Š” 011 ๋กœ ๋ฐ”๊ฟ”์ค„ ํ•„์š”๊ฐ€ ์—†์œผ๋ฏ€๋กœ, ๊ทธ๋ƒฅ 11๋กœ ๋‘๊ธฐ ์œ„ํ•ด์„œ i..

Algorithm/Baekjoon 2022.02.20

[๋ฐฑ์ค€] (Swift) 1737๋ฒˆ - 2์ง„์ˆ˜ 8์ง„์ˆ˜

๋ฌธ์ œ ๋งํฌ https://www.acmicpc.net/problem/1373 1373๋ฒˆ: 2์ง„์ˆ˜ 8์ง„์ˆ˜ ์ฒซ์งธ ์ค„์— 2์ง„์ˆ˜๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์ฃผ์–ด์ง€๋Š” ์ˆ˜์˜ ๊ธธ์ด๋Š” 1,000,000์„ ๋„˜์ง€ ์•Š๋Š”๋‹ค. www.acmicpc.net ๋‚ด๊ฐ€ ํ‘ผ ํ’€์ด ์ƒ๊ฐ๋ณด๋‹ค ์˜ค๋ž˜๊ฑธ๋ ธ๋‹ค. ๊ณ ๋ฏผ์Šค๋Ÿฌ์šด ๋ถ€๋ถ„์ด ์ƒ๋‹นํžˆ ๋งŽ์€ ๋ฌธ์ œ์ธ ๊ฒƒ๊ฐ™๋‹ค. ๋‚˜์ค‘์— ์ด๋Ÿฐ ์ง„๋ฒ•๋ฌธ์ œ๋Š” ๊ทธ๋ƒฅ ํ’€ ์ˆ˜ ์žˆ๋„๋ก 2์ง„๋ฒ•๊ณผ 10์ง„๋ฒ• ๊ณ„์‚ฐ๋ฒ• ๋ง๊ณ  3์ง„๋ฒ•, 8์ง„๋ฒ•, 16์ง„๋ฒ• ๋“ฑ ๊ธฐ๋ณธ์ ์œผ๋กœ ์ง„๋ฒ•๋ณ€ํ™˜์„ ์–ด๋–ค ๊ทœ์น™์œผ๋กœ ํ•ด์ฃผ์–ด์•ผ ํ•˜๋Š”์ง€ ์•Œ์•„๋‘๋Š”๊ฒƒ์ด ์ค‘์š”ํ•  ๊ฒƒ ๊ฐ™๋‹ค. (8์ง„๋ฒ• ์–ด์ผ€ ๊ตฌํ•˜๋Š”์ง€ ๋ชฐ๋ผ์„œ ์ฐพ์•„๋ณธ 1์ธ.... ํ•˜... ๋ฌด์‹๊ทธ์ž์ฒด๋‹ค ใ… ใ…  ) ์ง„๋ฒ• ๊ตฌํ•˜๋Š” ๋ฐฉ๋ฒ• ๊ธฐ๋ณธ์ ์œผ๋กœ ์•Œ์•„์•ผํ• ๋“ฏ 3์ž๋ฆฌ์”ฉ ๋Š์–ด์„œ 2^0, 2^1, 2^2 ์—ฐ์‚ฐ์œผ๋กœ 2์ง„๋ฒ• ๊ตฌํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ๊ตฌํ•ด์ค€ ๋’ค, ๊ฐ์ž๋ฆฌ์— ๋„ฃ์–ด์ฃผ๋Š”๊ฑฐ์ž„ ..

Algorithm/Baekjoon 2022.02.20

[๋ฐฑ์ค€] (Swift) 9613๋ฒˆ - GCDํ•ฉ

๋ฌธ์ œ ๋งํฌ https://www.acmicpc.net/problem/9613 9613๋ฒˆ: GCD ํ•ฉ ์ฒซ์งธ ์ค„์— ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค์˜ ๊ฐœ์ˆ˜ t (1 ≤ t ≤ 100)์ด ์ฃผ์–ด์ง„๋‹ค. ๊ฐ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋Š” ํ•œ ์ค„๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๋‹ค. ๊ฐ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋Š” ์ˆ˜์˜ ๊ฐœ์ˆ˜ n (1 ์ตœ๋Œ€๊ณต์•ฝ์ˆ˜๊ตฌํ•  ๋•Œ ์‚ฌ์šฉ (์œ ํด๋ฆฌ๋“œ ํ˜ธ์ œ๋ฒ•) input์— ๋‹ด๊ฒจ์žˆ๋Š” ์ˆ˜๋“ค์˜ GCD๋ฅผ ๊ตฌํ•ด์ฃผ๊ณ  ๋”ํ•ด์„œ ์ถœ๋ ฅํ•ด์คŒ let n = Int(readLine()!)! func gcd(_ m: Int, _ n: Int) -> Int { if n == 0 { return m } else { return gcd(n, m%n) ..

Algorithm/Baekjoon 2022.02.20

[๋ฐฑ์ค€] (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
๋ฐ˜์‘ํ˜•