본문 바로가기

백준1056

백준 10610 30 1 2 3 4 5 6 7 8 9 10 11 s=input() tmp=[] for i in s: tmp.append(int(i)) flag_zero= (tmp.count(0)!=0) flag_three= (sum(tmp)%3==0) if flag_three and flag_zero: tmp=sorted(tmp, reverse=True) for i in tmp: print(i,end='') else : print(-1) cs 일단 30의 배수가 되려면 3의배수이면서 10의배수여야하는데요 flag_zero는 입력받은값에 0이 없으면 10의 배수를 만들지못함을 이용 flag_three는 각 자리수의 합이 3의 배수이면 그 수도 3의 배수라는걸 이용 문제에서 가장 큰 값을 원하니 정렬할때 reverse=True .. 2021. 12. 8.
백준 10384 팬그램 1 2 3 4 5 6 7 8 9 10 11 for _ in range(int(input())): s=input() s=s.lower() tmp=[0]*26 for i in s: if i.isalpha(): tmp[ord(i)-97]+=1 if min(tmp)>=3: print("Case %d: Triple pangram!!!"%(_+1)) elif min(tmp)>=2: print("Case %d: Double pangram!!"%(_+1)) elif min(tmp)>=1: print("Case %d: Pangram!"%(_+1)) else :print("Case %d: Not a pangram"%(_+1)) cs 2021. 12. 8.
백준 9417 최대 GCD 1 2 3 4 5 6 7 8 9 10 11 12 def gcd(a,b): if(b==0): return a else: return gcd(b,a%b) for _ in range(int(input())): tmp=list(map(int, input().split())) ans=[] for i in range(len(tmp)): for j in range(i+1,len(tmp)): ans.append(gcd(max(tmp[i],tmp[j]),min(tmp[i],tmp[j]) ) ) print(max(ans)) Colored by Color Scripter cs 1. GCD 구하는 함수를 짠다. 2. tmp 리스트의 숫자들을 두개씩 짝지어서 GCD를 구한후 ans 리스트에 넣고 그 최대값을 출력하면 됩니다. .. 2021. 12. 8.
백준 11004 k번째 수 1 2 3 4 n,k=map(int,input().split()) tmp=list(map(int,input().split())) tmp.sort() print(tmp[k-1]) cs 내장함수로 쉽게 되긴하는데.. 아마 추가 Test Case 있으면 통과 안돼지 싶어요 2021. 12. 6.
백준 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.