본문 바로가기

백준1056

백준 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.
백준 7513 준살 프로그래밍 대회 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 testCase=int(input()) ansList=[] for i in range(testCase): print("Scenario #%d:"%(i+1)) wordCount=int(input()) words=[] for j in range(wordCount): words.append(input()) for j in range(int(input())): tmp=list(map(int, input().split())) ans="" for k in range(1,len(tmp)): ans+=words[tmp[k]] print(ans) print() Colored by Color Scripter cs 2021. 12. 3.
백준 5533 유니크 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 scores=[[],[],[]] n=int(input()) for i in range(n): a,b,c=map(int,input().split()) scores[0].append(a) scores[1].append(b) scores[2].append(c) ans=[] for i in range(n): res=0 for j in range(3): if scores[j].count(scores[j][i])==1 : res+=scores[j][i] ans.append(res) for i in ans: print(i) Colored by Color Scripter cs 2021. 12. 3.
백준 5426 비밀 편지 1 2 3 4 5 6 7 8 9 10 import math n=int(input()) for _ in range(n): tmp="" s=input() arrn=int(math.sqrt(len(s))) for i in range(arrn): for j in range(arrn): tmp+=s[arrn*(j+1)-(i+1)] print(tmp) cs 2021. 12. 3.
백준 2669 직사각형 네개의 합집합의 면적 구하기 1 2 3 4 5 6 7 8 9 10 arr= [[0 for col in range(101)] for row in range(101)] for i in range(4): a,b,c,d=map(int,input().split()) for j in range(a,c): for k in range(b,d): arr[j][k]=1 mysum=0 for i in range(101): mysum+=sum(arr[:][i]) print(mysum) Colored by Color Scripter cs 2021. 12. 3.
백준 10804 카드 역배치 1 2 3 4 5 6 7 tmp=[i+1 for i in range(20)] for i in range(10): a,b=map(int, input().split()) a-=1 b-=1 tmp[a:b+1]=tmp[a:b+1][::-1] print(*tmp) cs python에서 list[::-1]를 이용해서 쉽게 구현가능합니다. https://stackoverflow.com/questions/41430791/python-list-error-1-step-on-1-slice 2021. 12. 3.