본문 바로가기

python-algorithm1413

[백준] 2153 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 import sys import math s=sys.stdin.readline() cnt=0 for i in range(len(s)-1): if 96 2021. 1. 7.
[백준] 2037 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 import sys a,b=map(int, sys.stdin.readline().split()) s=sys.stdin.readline() cnt=0 for i in range(len(s)-1): if s[i]==' ' or s[i]== 'A' or s[i]== 'D' or s[i]== 'G' or s[i]== 'J' or s[i]== 'M' or s[i]== 'P' or s[i]== 'T' or s[i]== 'W': cnt+=a elif s[i]=='B' or s[i]== 'E' or s[i]== 'H' or s[i]== 'K' or s[i]== 'N' or s[i]== 'Q' or s[i]== 'U' or s[i]==.. 2021. 1. 6.
[백준] 2028 1 2 3 4 5 6 7 import sys for _ in range(int(sys.stdin.readline())): t=(sys.stdin.readline()) jagi=(int (t))**2 jagi= jagi%(10**(len(t)-1)) if jagi == int(t): print("YES") else: print("NO") cs 2021. 1. 6.
[백준] 1919 1 2 3 4 5 6 7 8 9 10 11 12 13 import sys s1=sys.stdin.readline() s2=sys.stdin.readline() tmp=[0]*26 tmp1=[0]*26 cnt=0 for i in range(len (s1)-1): tmp[ ord (s1[i]) -97 ] +=1 for i in range(len (s2)-1): tmp1[ ord (s2[i]) -97 ] +=1 for i in range(26): cnt+=abs(tmp[i]-tmp1[i]) print(cnt) cs 처음엔 순서가 중요한줄 알았는데 사실 순서는 별 의미가없고 알파벳별로 갯수만 체크하시면 됩니더 2021. 1. 6.
[백준] 1871 1 2 3 4 5 6 7 import sys for _ in range(int(sys.stdin.readline())): l,d=sys.stdin.readline().split('-') cnt= (ord (l[0])-65)*(26**2) + (ord(l[1])-65)*26+ord (l[2])-65 d= int(d) if abs(cnt-d)>100: print("not nice") else: print("nice") Colored by Color Scripter cs 2021. 1. 6.
[백준] 1813 1 2 3 4 5 6 7 8 9 10 11 12 import sys n=int(sys.stdin.readline()) hs=list(map(int,sys.stdin.readline().split())) tmp=[0]*100001 cnt=0 checker=0 for i in range(n): tmp[hs[i]]+=1 for i in range(len(tmp)): if tmp[i]==i: cnt=i; checker=1 if checker==0 : print(-1); exit() else: print(cnt) cs 말장난 같다고 할까요? 구현 능력보다는 명제를 찬찬히 읽어보시고 구현 하는 방식에 대해서 고민하시면 쉽게 풀 수 있습니다. 2021. 1. 6.
[백준] 1773 1 2 3 4 5 6 7 8 import sys n,c=map(int, sys.stdin.readline().split()) firework=[0]*(c+1) for _ in range(n): pok=int(sys.stdin.readline()) for i in range(c+1): if i%pok==0: firework[i]=1 print(sum(firework)-1) cs 시간초과나서 pypy 3로 돌렸습니다. 죄송합니다 시간줄여서 해볼게요 2021. 1. 6.
[백준] 1731 1 2 3 4 5 6 7 import sys n=int(sys.stdin.readline()) tmp=[] for _ in range(n): tmp.append(int(sys.stdin.readline())) if (tmp[1]-tmp[0])== (tmp[2]-tmp[1]): print( tmp[-1]+tmp[1]-tmp[0]) elif (tmp[1]%tmp[0])== (tmp[2]%tmp[1]): print( tmp[-1]*tmp[1]//tmp[0]) cs 어릴 때 배우셨던 등차, 등비 수열 조건? 점화식? 생각해보시면서 구현하시면 쉽습니다. 2021. 1. 6.
[백준] 1681 1 2 3 4 5 6 7 8 9 10 11 import sys a,b=sys.stdin.readline().split() a=int(a) cnt=0 n=0 while cnt!=a: n+=1 if b in str(n): continue cnt+=1 print(n) cs 본문 밑에 있는 힌트를 보시면 쉽고 python은 문자열 다루는게 다른 언어에 비해 쉬운편이라 쉽게 풀 수 있습니다. 2021. 1. 6.
[백준] 1668 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 import sys n=int(sys.stdin.readline()) tmp=[] for _ in range(n): tmp.append(int(sys.stdin.readline())) leftmax=tmp[0] rightmax=tmp[len(tmp)-1] cntLeft=1 cntRight=1 for i in range(n): if tmp[i]>leftmax : leftmax=tmp[i]; cntLeft+=1 for i in range(n): if tmp[n-1-i]>rightmax : rightmax=tmp[n-1-i]; cntRight+=1 print(cntLeft) print(cntRight) Colored by Color Scripte.. 2021. 1. 6.
[백준] 1568 1 2 3 4 5 6 7 8 9 10 11 12 13 import sys n=int(sys.stdin.readline()) tmp=0 for _ in range(99999): if n 0: if n-cnt 2021. 1. 6.
[백준] 1551 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 import sys def solution(A): tmp=[] for i in range(len(A)-1): tmp.append(A[i+1]-A[i]) A=tmp return A n,t = map(int, sys.stdin.readline().split()) A=list(map(int, sys.stdin.readline().split(","))) for _ in range(t): A=solution(A) for i in range(len(A)): if i!=len(A)-1:print(A[i],end=',') else: print(A[i]) cs solution 에 해당하는 우선 i+1항에서 i항을 뺀 것이 새로운 수열이고 그리고 다른 문제들.. 2021. 1. 6.