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

Algorithm/Baekjoon 149

[๋ฐฑ์ค€] (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

[๋ฐฑ์ค€] (Swift) 17413๋ฒˆ - ๋‹จ์–ด๋’ค์ง‘๊ธฐ2

๋ฌธ์ œ ๋งํฌ https://www.acmicpc.net/problem/17413 17413๋ฒˆ: ๋‹จ์–ด ๋’ค์ง‘๊ธฐ 2 ๋ฌธ์ž์—ด S๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, ์ด ๋ฌธ์ž์—ด์—์„œ ๋‹จ์–ด๋งŒ ๋’ค์ง‘์œผ๋ ค๊ณ  ํ•œ๋‹ค. ๋จผ์ €, ๋ฌธ์ž์—ด S๋Š” ์•„๋ž˜์™€๊ณผ ๊ฐ™์€ ๊ทœ์น™์„ ์ง€ํ‚จ๋‹ค. ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž('a'-'z'), ์ˆซ์ž('0'-'9'), ๊ณต๋ฐฑ(' '), ํŠน์ˆ˜ ๋ฌธ์ž('')๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ www.acmicpc.net ๋‚ด๊ฐ€ ํ‘ผ ํ’€์ด ํƒœ๊ทธ๋กœ ๊ตฌ๋ณ„ํ•ด์•ผํ•˜๋Š” ๋ฌธ์ œ์ธ๊ฒƒ์€ ์•Œ์•˜์ง€๋งŒ while๋ฌธ๊ณผ if ๋ฌธ์„ ์ค‘์ฒฉํ•ด์„œ ์ƒˆ๋กœ์šด array์— ๋„ฃ์–ด์ฃผ๋ฉด์„œ ๋ฌธ์ œ๋ฅผ ํ’€๋ ค๊ณ ํ–ˆ๋‹ค. ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ๋„ˆ๋ฌด ๋งŽ์ด ์ฐจ์ง€ํ•  ๊ฒƒ ๊ฐ™๋‹ค. ๊ณ ๋ฏผํ•ด๋ณด๋‹ค๊ฐ€ ์ธํ„ฐ๋„ท์„ ์กฐ๊ธˆ ์ฐพ์•„๋ณด๋‹ˆ ์ผ๋ฐ˜ string์œผ๋กœ ๋”ํ•ด์ฃผ๊ณ , ์ดˆ๊ธฐํ™”ํ•ด์ฃผ๊ณ , print(terminator) ๊ธฐ๋Šฅ์„ ์ด์šฉํ•ด์„œ ํ•œ์ค„๋กœ ์ถœ๋ ฅํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค. terminator ๊ธฐ๋Šฅ..

Algorithm/Baekjoon 2022.02.07

[๋ฐฑ์ค€] (Swift) 10866๋ฒˆ - ๋ฑ(deque)

๋ฌธ์ œ ๋งํฌ https://www.acmicpc.net/problem/10866 10866๋ฒˆ: ๋ฑ ์ฒซ์งธ ์ค„์— ์ฃผ์–ด์ง€๋Š” ๋ช…๋ น์˜ ์ˆ˜ N (1 ≤ N ≤ 10,000)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ N๊ฐœ์˜ ์ค„์—๋Š” ๋ช…๋ น์ด ํ•˜๋‚˜์”ฉ ์ฃผ์–ด์ง„๋‹ค. ์ฃผ์–ด์ง€๋Š” ์ •์ˆ˜๋Š” 1๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 100,000๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™๋‹ค. ๋ฌธ์ œ์— ๋‚˜์™€์žˆ์ง€ www.acmicpc.net ๋‚ด๊ฐ€ ํ‘ผ ํ’€์ด ์ฝ”๋“œ ๊ธธ์ด ์ ์ˆ˜์—์„œ B๋ฅผ ๋ฐ›์•˜๋‹ค. ์ด๋ฅผ ์ค„์ผ ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•, ๋” ํšจ์œจ์ ์ธ ์ฝ”๋”ฉ ๋ฐฉ๋ฒ•์ด ๋ญ๊ฐ€ ์žˆ์„๊นŒ? import Foundation let n = Int(readLine()!)! var answer: [String] = [] for _ in 0..

Algorithm/Baekjoon 2022.02.06

[๋ฐฑ์ค€] (Swift) 1158๋ฒˆ - ์š”์„ธํ‘ธ์Šค ๋ฌธ์ œ

๋ฌธ์ œ ๋งํฌ https://www.acmicpc.net/problem/1158 1158๋ฒˆ: ์š”์„ธํ‘ธ์Šค ๋ฌธ์ œ ์ฒซ์งธ ์ค„์— N๊ณผ K๊ฐ€ ๋นˆ ์นธ์„ ์‚ฌ์ด์— ๋‘๊ณ  ์ˆœ์„œ๋Œ€๋กœ ์ฃผ์–ด์ง„๋‹ค. (1 ≤ K ≤ N ≤ 5,000) www.acmicpc.net ๋‚ด๊ฐ€ ํ‘ผ ํ’€์ด idx๋ฅผ pop, push๋ฅผ ํ™œ์šฉํ•˜์—ฌ ๊ตฌํ˜„ํ•˜๋ ค๊ณ  ํ–ˆ์ง€๋งŒ ์ €๋ ‡๊ฒŒ ๋ง์…ˆ๊ณผ count๋ฅผ ํ™œ์šฉํ•œ ๋‚˜๋ˆ—์…ˆ์œผ๋กœ ๊ทœ์น™์„ ์ฐพ์„ ์ˆ˜ ์žˆ๋‹ค. ์ด ๋ถ€๋ถ„์—์„œ ์กฐ๊ธˆ ๋ง‰ํ˜”์ง€๋งŒ, ๊ทœ์น™์„ ์ฐพ์œผ๋‹ˆ ์™„์ „ํžˆ ์ดํ•ด๊ฐ€ ๊ฐ”๋‹ค. import Foundation let input = readLine()!.split(separator: " ").map { Int($0)! } var nums: [Int] = [] var answer: [Int] = [] var idx = input[1] - 1 for i in..

Algorithm/Baekjoon 2022.02.05

[๋ฐฑ์ค€] (Swift) 10845๋ฒˆ - ํ

๋ฌธ์ œ ๋งํฌ https://www.acmicpc.net/problem/10845 10845๋ฒˆ: ํ ์ฒซ์งธ ์ค„์— ์ฃผ์–ด์ง€๋Š” ๋ช…๋ น์˜ ์ˆ˜ N (1 ≤ N ≤ 10,000)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ N๊ฐœ์˜ ์ค„์—๋Š” ๋ช…๋ น์ด ํ•˜๋‚˜์”ฉ ์ฃผ์–ด์ง„๋‹ค. ์ฃผ์–ด์ง€๋Š” ์ •์ˆ˜๋Š” 1๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 100,000๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™๋‹ค. ๋ฌธ์ œ์— ๋‚˜์™€์žˆ์ง€ www.acmicpc.net ๋‚ด๊ฐ€ ํ‘ผ ํ’€์ด ์ด์ „์— ํ’€์—ˆ๋˜ ์Šคํƒ, ์—๋””ํ„ฐ์™€ ๋น„์Šทํ•œ ๊ตฌ์กฐ๋กœ ์ด๋ฃจ์–ด์ง€๋Š” ์ฝ”๋“œ์ด๋ฏ€๋กœ ๋ณ„ ๊ณ ๋ฏผ์—†์ด ๋ฐ”๋กœ ํ•ด๊ฒฐ ํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค. import Foundation let n = Int(readLine()!)! var answer: [String] = [] for _ in 0..

Algorithm/Baekjoon 2022.02.04

[๋ฐฑ์ค€] (Swift) 1406๋ฒˆ - ์—๋””ํ„ฐ

๋ฌธ์ œ๋งํฌ https://www.acmicpc.net/problem/1406 1406๋ฒˆ: ์—๋””ํ„ฐ ์ฒซ์งธ ์ค„์—๋Š” ์ดˆ๊ธฐ์— ํŽธ์ง‘๊ธฐ์— ์ž…๋ ฅ๋˜์–ด ์žˆ๋Š” ๋ฌธ์ž์—ด์ด ์ฃผ์–ด์ง„๋‹ค. ์ด ๋ฌธ์ž์—ด์€ ๊ธธ์ด๊ฐ€ N์ด๊ณ , ์˜์–ด ์†Œ๋ฌธ์ž๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ์œผ๋ฉฐ, ๊ธธ์ด๋Š” 100,000์„ ๋„˜์ง€ ์•Š๋Š”๋‹ค. ๋‘˜์งธ ์ค„์—๋Š” ์ž…๋ ฅํ•  ๋ช…๋ น์–ด์˜ ๊ฐœ์ˆ˜ www.acmicpc.net ๋‚ด๊ฐ€ ํ‘ผ ํ’€์ด (1) - ์‹œ๊ฐ„์ดˆ๊ณผ! ์ปค์„œ๋ฅผ ์›€์ง์—ฌ์•ผํ•œ๋‹ค๋Š” ์ƒ๊ฐ์œผ๋กœ ๋ฐฐ์—ด์—์„œ ์ธ๋ฑ์Šค๋ฅผ ์™”๋‹ค๊ฐ”๋‹ค ํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ํ’€์—ˆ์Œ. ๋ฐฐ์—ด์„ ์›€์ง์ด๊ณ , ํ•˜๋‚˜์˜ ์—ฐ์‚ฐ์ด ์ˆ˜ํ–‰๋ ๋•Œ๋งˆ๋‹ค ์ธ๋ฑ์Šค์™€ ๋ฌธ์ž์—ด์„ ๋ฐ”๊พธ์–ด์ค˜์•ผํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์‹œ๊ฐ„์ดˆ๊ณผ๊ฐ€ ๋ฐœ์ƒํ•œ ๊ฒƒ ๊ฐ™์Œ. import Foundation var text = Array(readLine()!) let n = Int(readLine()!)! var cursor = text..

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