이론
📖 버블 정렬
📖 선택 정렬
문제풀이
📖 백준 1377 (🔗백준 1377 문제)
✏ 문제해석=swap이 한번도 일어나지 않을때가(정렬이 완료될때가) 언제인지(몇번째루프인지) 알아내기.
✏ sort()의 시간복잡도는 O(nlogn)이다.
✏ 시간초과에 유의.
✏ 버블정렬이기 때문에 swap수행 시 데이터가 이동하는 최대거리가 1이 된다. 따라서, 정렬 전과 정렬 후(sort함수이용)의 index를 비교하여, 가장 많이 이동한 값 찾기.
#문제해석=swap이 한번도 일어나지 않을때가(정렬이 완료될때가) 언제인지(몇번째루프인지) 알아내기.
#sort()의 시간복잡도는 O(nlogn)이다.
import sys
input=sys.stdin.readline
n=int(input())
a=[0]*n
arr=[]
for i in range(n):
a[i]=(int(input()),i)
sort_a=sorted(a)
for i in range(n):
arr.append(sort_a[i][1]-i)
print(max(arr)+1)
📖 백준 1427 (🔗백준 1427 문제)
n=list(map(int,input()))
n.sort(reverse=True)
for i in n:
print(i,end="")
◼ 참고사항