[Swift] 프로그래머스 12941 최솟값 만들기
·
📝 코테/프로그래머스
import Foundation func solution(_ A: [Int], _ B: [Int]) -> Int { var ans = 0 let a = A.sorted(by: ) for i in 0..
[Swift] 백준 11650 좌표 정렬하기
·
📝 코테/BOJ
import Foundation let N = Int(readLine()!)! var tuples = [(x: Int, y: Int)]() for _ in 1...N { let xy = readLine()!.components(separatedBy: " ").map { Int($0)! } let x = xy[0] let y = xy[1] tuples.append((x, y)) } tuples = tuples.sorted(by: { $0.y < $1.y }).sorted(by: { $0.x < $1.x }) for tuple in tuples { print(tuple.x, tuple.y) } 튜플로 풀었다. 정렬할때는 정렬하는 순서를 유의하는게 좋을 것 같다.
[Swift] 백준1181
·
📝 코테/BOJ
import Foundation let n = Int(readLine()!)! var arr = [String]() for _ in 0 ..< n { let input = readLine()! arr.append(input) } // 중복제거 arr = Array(Set(arr)) // 길이사전순 + 짧은 순 arr = arr.sorted(by: { $0 < $1 }).sorted(by: { $0.count < $1.count }) for string in arr { print(string) }
JerryiOS
'정렬' 태그의 글 목록