Skip to content

[Algorithm] 나이순 정렬 #213

Description

@hwangJi-dev

💬 문제

https://www.acmicpc.net/problem/10814


💬 Idea

  • 딕셔너리에 나이를 key값으로 설정하고, 먼저 가입한 순서대로 value를 저장하기 위해 value는 array 타입으로 설정한다.
  • 딕셔너리를 나이가 작은 순으로 정렬한 뒤 해당 나이의 회원을 가입한 순서대로 출력한다.

💬 풀이

import Foundation
func solution10814(){letn=Int(readLine()!)!
varojDict:[Int:[String]]=[:]for_in1...n {leto=readLine()!.components(separatedBy:.whitespaces)letage=Int(o[0])!
ifojDict[age]==nil{ojDict[age]=[o[1]]}else{ojDict[age]?.append(o[1])}}foriin ojDict.sorted(by:{ $0.key < $1.key }){forjin i.value {print("\(i.key)\(j)")}}}solution10814()

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions