목록티스토리 포스트 (220)
Where who wants to meet someone
난이도 실버 II 문제 https://www.acmicpc.net/problem/18870 18870번: 좌표 압축 수직선 위에 N개의 좌표 X1, X2, ..., XN이 있다. 이 좌표에 좌표 압축을 적용하려고 한다. Xi를 좌표 압축한 결과 X'i의 값은 Xi > Xj를 만족하는 서로 다른 좌표 Xj의 개수와 같아야 한다. X1, X2, ..., XN에 www.acmicpc.net 내 답안 let n = Int(readLine()!)! var arr = readLine()!.split(separator: " ").map { Int($0)! } var dictionary = [Int:Int]() var count = 0 for i in arr.sorted() { if dictionary[i] == ni..
난이도 실버 V 문제 https://www.acmicpc.net/problem/10814 10814번: 나이순 정렬 온라인 저지에 가입한 사람들의 나이와 이름이 가입한 순서대로 주어진다. 이때, 회원들을 나이가 증가하는 순으로, 나이가 같으면 먼저 가입한 사람이 앞에 오는 순서로 정렬하는 프로그램을 www.acmicpc.net 내 답안 struct Person { var order: Int var age: Int var name: String } var arr = [Person]() for count in 1...Int(readLine()!)! { let input = readLine()!.split(separator: " ").map { String($0) } arr.append(Person(order..
난이도 실버 V 문제 https://www.acmicpc.net/problem/1181 1181번: 단어 정렬 첫째 줄에 단어의 개수 N이 주어진다. (1 ≤ N ≤ 20,000) 둘째 줄부터 N개의 줄에 걸쳐 알파벳 소문자로 이루어진 단어가 한 줄에 하나씩 주어진다. 주어지는 문자열의 길이는 50을 넘지 않는다. www.acmicpc.net 내 답안 var alphabetSet = Set() for _ in 1...Int(readLine()!)! { alphabetSet.insert(readLine()!) } let sortedSet = alphabetSet.sorted(by: { first, second in if first.count < second.count { return true } else ..
난이도 실버 V 문제 https://www.acmicpc.net/problem/11651 11651번: 좌표 정렬하기 2 첫째 줄에 점의 개수 N (1 ≤ N ≤ 100,000)이 주어진다. 둘째 줄부터 N개의 줄에는 i번점의 위치 xi와 yi가 주어진다. (-100,000 ≤ xi, yi ≤ 100,000) 좌표는 항상 정수이고, 위치가 같은 두 점은 없다. www.acmicpc.net 내 답안 var array: [(Int, Int)] = [] for _ in 1...Int(readLine()!)! { let input = readLine()!.split(separator: " ").map { Int($0)! } array.append((input[1], input[0])) } array.sort(by:
난이도 실버 V 문제 https://www.acmicpc.net/problem/11650 11650번: 좌표 정렬하기 첫째 줄에 점의 개수 N (1 ≤ N ≤ 100,000)이 주어진다. 둘째 줄부터 N개의 줄에는 i번점의 위치 xi와 yi가 주어진다. (-100,000 ≤ xi, yi ≤ 100,000) 좌표는 항상 정수이고, 위치가 같은 두 점은 없다. www.acmicpc.net 내 답안 var array: [(Int, Int)] = [] for _ in 1...Int(readLine()!)! { let input = readLine()!.split(separator: " ").map { Int($0)! } array.append((input[0], input[1])) } array.sort(by:..