Development Project

[ Baekjoon - 단계별로 풀어보기(06/03~06/06) ] - 11단계 : 정렬 본문

CodingTest/Baekjoon

[ Baekjoon - 단계별로 풀어보기(06/03~06/06) ] - 11단계 : 정렬

나를 위한 시간 2022. 6. 3. 16:37
  • 2750 : 수 정렬하기
n=int(input())
l=[int(input()) for _ in range(n)]
for i in range(n):
    print(sorted(l)[i])

 

  • 2751 : 수 정렬하기 2
import sys
arr=[int(sys.stdin.readline().rstrip()) for i in range(int(input()))]
arr.sort()
for i in arr:
    sys.stdout.write(str(i)+'\n')

 

  • 10989 : 수 정렬하기 3
from sys import stdin

input = stdin.readline().strip
N = int(input())
numbers = []
for i in range(10001):
  numbers.append(0)

for i in range(N):
  numbers[int(stdin.readline().rstrip())] += 1

for index, count in enumerate(numbers):
  if count != 0:
    for _ in range(count):
      print(index)

 

  • 2108 : 통계학
import sys
from collections import Counter
n = int(sys.stdin.readline())
li = []
for _ in range(n):
    li.append(int(sys.stdin.readline()))

print(round(sum(li)/n))
 
li.sort()
print(li[n//2])

cnt_li = Counter(li).most_common()
if len(cnt_li) > 1 and cnt_li[0][1]==cnt_li[1][1]:
    print(cnt_li[1][0])
else:
    print(cnt_li[0][0])

print(max(li)-min(li))
#
import collections as c
n,*l=map(int,open(0))
l.sort()
t=c.Counter(l).most_common(2)
print(round(sum(l)/n),l[n//2],t[-(t[0][1]==t[-1][1])][0],l[-1]-l[0])

 

  • 1427 : 소트인사이드
def quick_sort(arr):
    if len(arr) <= 1:
        return arr
    pivot = arr[len(arr) // 2]
    lesser_arr, equal_arr, greater_arr = [], [], []
    for num in arr:
        if num > pivot:
            lesser_arr.append(num)
        elif num < pivot:
            greater_arr.append(num)
        else:
            equal_arr.append(num)
    return quick_sort(lesser_arr) + equal_arr + quick_sort(greater_arr)

arr=list(map(int, input()))
for i in quick_sort(arr):
    print(i,end="")

 

  • 11650 : 좌표 정렬하기
import sys
input = sys.stdin.readline
n=int(input())
a=[]
for i in range(n):
    x, y = map(int, input().split())
    a.append([x, y])
a.sort(key= lambda x: (x[0],x[1]))
for i in range(n):
    print(a[i][0], a[i][1])

 

  • 11651 : 좌표 정렬하기 2
import sys
input = sys.stdin.readline
n=int(input())
a=[]
for i in range(n):
    x, y = map(int, input().split())
    a.append([y,x])
a.sort(key= lambda x: (x[0],x[1]))
for i in range(n):
    print(a[i][1], a[i][0])

 

  • 1181 : 단어 정렬
word_list = []
for i in range(int(input())):
    word_list.append(input())

word_list = list(set(word_list))
word_list.sort()
word_list.sort(key = lambda x : len(x))

for word in word_list:
    print(word)

 

  • 10814 : 나이순 정렬
import sys
input = sys.stdin.readline

l=[]
for i in range(int(input())):
    a,b=input().split()
    l.append([int(a),b])
l=sorted(l, key=lambda x:x[0])
for i in range(len(l)):
    print(l[i][0],l[i][1])

 

  • 18870 : 좌표 압축 
import sys
input=sys.stdin.readline

n=int(input())
l=list(map(int,input().split()))[:n]
sort_l=sorted(set(l))
l_dict={i:v for v,i in enumerate(sort_l)}
for i in l:
    print(f'{l_dict[i]}',end=" ")
Comments