본문 바로가기

백준1064

백준 10867 중복 빼고 정렬하기 1 2 3 4 5 n=int(input()) tmp=list(map(int,input().split())) tmp=set(tmp) tmp=sorted(list(tmp)) print(*tmp) cs 2021. 12. 6.
백준 7785 회사에 있는 사람 1 2 3 4 5 6 7 8 9 10 tmp=[] for i in range(int(input())): a,b=map(str, input().split()) if b=='enter' : tmp.append(a) elif b=='leave': tmp.remove(a) for i in sorted(tmp,reverse=True): print (i) cs 2021. 12. 6.
백준 5800 성적 통계 1 2 3 4 5 6 7 8 9 10 11 12 for i in range(int(input())): tmp=list(map(int,input().split())) listLen=tmp[0] tmp.pop(0) mymax=max(tmp) mymin=min(tmp) tmp=sorted(tmp) gap=0 for j in range(1,len(tmp)): gap=max(tmp[j]-tmp[j-1],gap) print("Class %d"%(i+1)) print("Max %d, Min %d, Largest gap %d"%(mymax,mymin,gap)) cs 2021. 12. 6.
백준 5671 호텔 방 번호 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 while 1: cnt=0 try: a,b=map(int, input().split()) for i in range(a,b+1): tmp=['0','1','2','3','4','5','6','7','8','9'] tmp2=[0]*10 i=str(i) for j in i: tmp2[int(j)]+=1 flagDuplicate=0 for j in tmp2: if j>1:flagDuplicate=1 if flagDuplicate==0 : cnt+=1 print(cnt) except : break Colored by Color Scripter cs 2021. 12. 6.
백준 5635 생일 1 2 3 4 5 6 7 8 9 10 tmp=[] for i in range(int(input())): name,dd,mm,yy=input().split() dd=int(dd) mm = int(mm) yy= int(yy) tmp.append([name,yy,mm,dd]) tmp=sorted(tmp, key=lambda x: (x[1], x[2], x[3])) print(tmp[-1][0]) print(tmp[0][0]) Colored by Color Scripter cs sort는 lambda를 통해서 하시면되고 주의할만한건 생년 월 일 을 각각 type casting해주셔야합니다. 그냥 input()으로 받으면 기본 type이 str이라서 순서가 다르게 (1 , 10 ,11, 12 ,2, 3,4, .... 2021. 12. 6.
백준 2822 점수 계산 1 2 3 4 5 6 7 8 9 10 11 tmp=[] for i in range(8): tmp.append( [i+1, int(input())]) tmp=sorted(tmp,key=lambda x: x[1]) ans=0 idx=[] for i in range(5): ans+=tmp[i+3][1] idx.append(tmp[i+3][0]) print(ans) print (*sorted(idx)) cs 2021. 12. 6.
백준 2693 N번째 큰 수 1 2 3 4 5 n=int(input()) for i in range(n): tmp=list(map(int,input().split())) tmp=sorted(tmp,reverse=True) print(tmp[2]) cs 2021. 12. 6.
백준 2417 정수 제곱근 1 2 3 import math n=int(input()) print( math.ceil(math.sqrt(n))) cs 내장함수를 이용하도록 합시다 ^^; 2021. 12. 6.
백준 1789 수들의 합 1 2 3 4 5 s=int(input()) cnt=1 while (cnt*(cnt+1))//2 2021. 12. 6.
백준 1769 3의 배수 1 2 3 4 5 6 7 8 9 10 11 n=input() cnt=0 while len(n)>1: cnt+=1 ans=0 for i in n: ans+=int(i) n=str(ans) print(cnt) if int(n)%3 ==0 : print("YES") else : print("NO") cs 2021. 12. 6.
백준 1292 쉽게 푸는 문제 1 2 3 4 5 6 7 a,b=map(int,input().split()) tmp=[] for i in range(1001): for j in range(i): tmp.append(i) #print(tmp) print(sum(tmp[a-1:b])) cs 2021. 12. 6.
14648 쿼리 맛보기 1 2 3 4 5 6 7 8 9 10 11 m,n=map(int, input().split()) myList=list(map(int, input().split())) for i in range(n): myQuery=list(map(int,input().split())) if myQuery[0]==1: print(sum(myList[myQuery[1]-1:myQuery[2]])) tmp=myList[myQuery[1]-1] myList[myQuery[1]-1]=myList[myQuery[2] - 1] myList[myQuery[2] - 1]=tmp if myQuery[0]==2: print(sum(myList[myQuery[1] - 1:myQuery[2]])-sum(myList[myQuery[3] - 1:.. 2021. 12. 6.