๐ป Algorithm/Swift
-
[Swift] ๋ฐฑ์ค 1260 DFS์ BFS (Graph Traversal)๐ป Algorithm/Swift 2023. 1. 31. 22:42
๐ ํ์ด ๐ฌ Code import Foundation struct Queue { fileprivate var array = [T]() public var isEmpty: Bool { return array.isEmpty } public mutating func enqueue(_ element: T) { array.append(element) } public mutating func dequeue() -> T? { if isEmpty { return nil } else { return array.removeFirst() } } } let input = readLine()!.split(separator: " ").map { Int(String($0))! } let n = input[0] let m = inp..
-
[Swift] ๋ฐฑ์ค 14490 ๋ฐฑ๋์ด (์ต๋๊ณต์ฝ์ GCM ๋ฌธ์ )๐ป Algorithm/Swift 2023. 1. 31. 22:41
๐ ํ์ด ๐ฌ Code let num = readLine()!.split(separator: ":").map { Int(String($0))! } let num1 = num[0] let num2 = num[1] let gcd = GCD(num1, num2) print("\(num1/gcd):\(num2/gcd)") func GCD(_ min:Int, _ max:Int) -> Int { let res = min % max if res == 0 { return max } return GCD(max, res) } 14490๋ฒ: ๋ฐฑ๋์ด n๊ณผ m์ด :์ ์ฌ์ด์ ๋๊ณ ์ฃผ์ด์ง๋ค. (1 ≤ n, m ≤ 100,000,000) www.acmicpc.net
-
[Swift] ๋ฐฑ์ค 2941 ํฌ๋ก์ํฐ์ ์ํ๋ฒณ (String)๐ป Algorithm/Swift 2023. 1. 31. 22:37
๐ ํ์ด ๐ฌ Code import Foundation let alpha = ["c=", "c-", "dz=", "d-", "lj", "nj", "s=", "z="] var word = readLine()! for i in alpha { word = word.replacingOccurrences(of: i, with: "*") } print(word.count) 2941๋ฒ: ํฌ๋ก์ํฐ์ ์ํ๋ฒณ ์์ ์๋ ์ด์์ฒด์ ์์ ํฌ๋ก์ํฐ์ ์ํ๋ฒณ์ ์ ๋ ฅํ ์๊ฐ ์์๋ค. ๋ฐ๋ผ์, ๋ค์๊ณผ ๊ฐ์ด ํฌ๋ก์ํฐ์ ์ํ๋ฒณ์ ๋ณ๊ฒฝํด์ ์ ๋ ฅํ๋ค. ํฌ๋ก์ํฐ์ ์ํ๋ฒณ ๋ณ๊ฒฝ ฤ c= ฤ c- dลพ dz= ฤ d- lj lj nj nj š s= ลพ z= www.acmicpc.net
-
[Swift] ๋ฐฑ์ค 1427 ์ํธ์ธ์ฌ์ด๋ (String)๐ป Algorithm/Swift 2023. 1. 31. 22:35
๐ ํ์ด ๐ฌ Code import Foundation var n = readLine()!.map{ Int(String($0))! } n.sort { $0 > $1 } print(n.map{ String($0) }.joined()) 1427๋ฒ: ์ํธ์ธ์ฌ์ด๋ ์ฒซ์งธ ์ค์ ์ ๋ ฌํ๋ ค๊ณ ํ๋ ์ N์ด ์ฃผ์ด์ง๋ค. N์ 1,000,000,000๋ณด๋ค ์๊ฑฐ๋ ๊ฐ์ ์์ฐ์์ด๋ค. www.acmicpc.net
-
[Swift] ๋ฐฑ์ค 4659 ๋น๋ฐ๋ฒํธ ๋ฐ์ํ๊ธฐ (String)๐ป Algorithm/Swift 2023. 1. 31. 22:33
๐ ํ์ด ๐ฌ Code import Foundation while (true) { let pw = readLine()! if pw == "end" { break } if pw.isPassedConditionA() && pw.isPassedConditionB() && pw.isPassedConditionC() { print(" is acceptable.") } else { print(" is not acceptable.") } } extension String { func isPassedConditionA() -> Bool { for alpha in self.map({ String($0) }) { if ["a", "e", "i", "o", "u"].contains(alpha) { return true } }..