본문 바로가기

백준1064

백준 12871 무한 문자열 1 2 3 4 5 6 7 8 9 10 11 # def gcd(x,y): # while (y) : x,y=y, x%y # return x s=input() t=input() lenS=len(s) lenT=len(t) s=s*lenT t=t*lenS if s==t : print(1) else : print(0) cs 2021. 12. 14.
백준 18917 수열과 쿼리 38 1 2 3 4 5 6 7 8 9 10 11 12 13 14 import sys n=int(sys.stdin.readline()) mysum=0 xor=0 for i in range(n): oper=list(map(int,sys.stdin.readline().split())) if oper[0]== 1: mysum+=oper[1] xor = xor^oper[1] elif oper[0]== 2 : mysum-=oper[1] xor=xor^oper[1] elif oper[0] == 3: print((mysum)) elif oper[0] == 4: print(xor) cs 2021. 12. 14.
백준 17176 암호해독기 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 import sys def cyper(n): if n==0 : ans=' ' elif n>=1 and n 2021. 12. 14.
백준 11068 회문인 수 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 def jinsu(a,b): tmp=[] while a>0: tmp.append(a%b) a=a//b tmp=tmp[::-1] return tmp def chk(s): for i in range(len(s)//2): if s[i]!= s[-i-1]: return False return True t=int(input()) for _ in range(t): cnt=False n=int(input()) for i in range(2,65): if chk(jinsu(n, i)): cnt=chk(jinsu(n,i)) break if cnt : print(1) else: print(0) cs B 진수로 바꾸는 함수.. 2021. 12. 9.
백준 16212 정열적인 정렬 1 2 3 4 import sys n=int(sys.stdin.readline()) tmp=list(map(int, sys.stdin.readline().split())) print(*sorted(tmp)) cs 2021. 12. 9.
백준 11170 0의 개수 1 2 3 4 5 6 7 dddt=int(input()) for i in range (t): ans=0 n,m=map(int, input().split()) for j in range(n,m+1): ans+=str(j).count('0') print(ans) cs 2021. 12. 9.
백준 11931 수 정렬하기 4 1 2 3 4 5 6 7 import sys tmp=[] for i in range(int(input())): tmp.append(int(sys.stdin.readline())) tmp.sort(reverse=True) for i in tmp: print(i) cs 2021. 12. 8.
백준 11728 배열 합치기 1 2 3 4 5 n,m=map(int, input().split()) tmp1=list(map(int,input().split())) tmp2=list(map(int,input().split())) tmp1.extend(tmp2) print(*sorted(tmp1)) cs 2021. 12. 8.
백준 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.