์•Œ๊ณ ๋ฆฌ์ฆ˜

๋ฐฑ์ค€ 10814 ๋ฌธ์ œํ’€์ด

ghtis1798 2021. 3. 20. 12:05

๐Ÿ“Œ๋ฌธ์ œ ์„ค๋ช…

10814 ๋ฌธ์ œ์„ค๋ช…
10814 ์ถœ๋ ฅ ์˜ˆ์‹œ

๐Ÿ“Œ๋ฌธ์ œ์ ‘๊ทผ๋ฐฉ์‹

enumerateํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•ด ํšŒ์›๋ณ„ ๋ฒˆํ˜ธ๋ฅผ ๋งค๊ธด ๋’ค ๋‚˜์ด์ˆœ์œผ๋กœ ์ •๋ ฌํ•˜๋ฉด ๋œ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ๋‹ค. ๋งŒ์•ฝ ๋‚˜์ด๊ฐ€ ๊ฐ™๋‹ค๋ฉด ๋งค๊ฒจ๋‘” ํšŒ์› ๋ฒˆํ˜ธ๋กœ ์ •๋ ฌ์„ ์‹ค์‹œํ•œ๋‹ค. ๋”ฐ๋ผ์„œ ์ •๋ ฌ์˜ ๊ธฐ์ค€๋ฅผ 2๊ฐœ๋กœ ์„ค์ •ํ–ˆ๋‹ค.

๐Ÿ“Œ๋ฌธ์ œํ’€์ด

1์ฐจ ์‹œ๋„

์‹คํŒจํ•œ ์ด์œ ๋Š” ๋‹ค๋ฅธ ๊ณณ์—์„œ ๋ฐœ์ƒํ–ˆ๋‹ค.

์ž…๋ ฅ๋ฐ›์„ ๋•Œ ๋‚˜์ด๊ฐ€ ๋ฌธ์ž๋กœ ์ž…๋ ฅ๋˜์—ˆ๋‹ค.

[(['21', 'Junkyu'], 1), (['21', 'Dohyun'], 2), (['20', 'Sunyoung'], 3)]

๋”ฐ๋ผ์„œ '21'๊ณผ '20'์„ ์ˆซ์ž๋กœ ๋ฐ”๊ฟ”์ฃผ๋‹ˆ ๋ฌธ์ œ ์—†์ด ํ†ต๊ณผํ–ˆ๋‹ค.

๋น„๊ตํ•  ๋•Œ๋Š” ๋ฐ˜๋“œ์‹œ ๋น„๊ตํ•˜๋Š” ๋Œ€์ƒ์˜ ํƒ€์ž…์ด ๋ฌด์—‡์ธ์ง€ ํ™•์ธํ•ด์•ผ๊ฒ ๋‹ค.

์†Œ์Šค์ฝ”๋“œ

import sys

n = int(sys.stdin.readline().rstrip())
input_list = [sys.stdin.readline().rstrip().split() for x in range(n)]
input_list = [(x,y) for x,y in enumerate(input_list, 1)]

def solution(input_list):
    input_list.sort(key = lambda value: (value[1][0], value[0]))

solution(input_list)
for answer in input_list:
    print(answer[1][0], answer[1][1])

์†Œ์Šค์ฝ”๋“œ

import sys

n = int(sys.stdin.readline().rstrip())
input_list = [sys.stdin.readline().rstrip().split() for x in range(n)]
input_list = [(y, enum) for enum,y in enumerate(input_list, 1)]

def solution(input_list):
    input_list.sort(key = lambda value: (int(value[0][0]), value[1]))

solution(input_list)
for answer in input_list:
    print(answer[0][0], answer[0][1])