본문 바로가기

python-algorithm1422

백준 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.
백준 10769 행복한지 슬픈지 1 2 3 4 5 6 7 s=input() smile=s.count(":-)") sad=s.count(":-(") if smile==0 and sad==0: print("none") elif smile>sad: print("happy") elif smile==sad: print("unsure") elif smile 2021. 12. 3.
백준 10426 기념일 2 1 2 3 4 5 6 7 import datetime mydate,celebrate=input().split() yy,mm,dd=map(int, mydate.split('-')) celebrate=int(celebrate)-1 dday=datetime.datetime(yy,mm,dd) dday=dday+datetime.timedelta(days=celebrate) print(dday.strftime("%Y-%m-%d")) cs 2021. 12. 3.
백준 9506 약수들의 합 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 def perfect(n): n=int(n) divide=[] for i in range(1,n//2+1): if n%i==0 : divide.append(i) if sum(divide)==n: print("%d ="%n,end='') for i in range(len(divide)): if i!=len(divide)-1:print(" %d "%divide[i],end='+') else : print(" %d"%divide[i]) else : print("%d is NOT perfect."%n) while 1: n=int(input()) if n==-1 : break perfect(n) Colored by Color Scripter cs 2021. 12. 3.