본문 바로가기

python-algorithm1413

[백준] 6376 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 import sys def factorial(n): ans=1 if n==0: return 1; for i in range(1,n+1): ans*=i return ans ans=0 print("n e") print("- -----------") for i in range(10): ans+=1/factorial(i) if ans>2.5: print("%d %.9f"%(i, ans)) elif ans==1 or ans==2 : print("%d %d"%(i, ans)) elif ans==2.5 : print("%d %.1f"%(i, ans)) cs 팩토리얼은 math 라이브러리에서 이용하셔도 돼요 natural log e 를 구하는 문제네요. 2021. 1. 10.
[백준] 6359 1 2 3 4 5 6 7 8 9 10 11 12 13 14 import sys def sangbeom(myarray,a): for i in range(len(myarray)): if i%a==0: if myarray[i]==1: myarray[i]=0 else: myarray[i]=1 return myarray for _ in range(int(sys.stdin.readline())): n=int(sys.stdin.readline()) tmp=[0]*(n+1) for i in range(1,n+1): sangbeom(tmp,i) tmp[0]=0 print(sum(tmp)) cs 2021. 1. 10.
[백준] 5988 1 2 3 4 5 import sys for _ in range(int(sys.stdin.readline())): n= int (sys.stdin.readline()) if n%2==0 : print("even") else: print("odd") cs 2021. 1. 10.
[백준] 5789 1 2 3 4 5 import sys for _ in range(int(sys.stdin.readline())): s=sys.stdin.readline() if s[len(s)//2] == s[len(s)//2 -1]: print("Do-it") else: print("Do-it-Not") cs 2021. 1. 10.
[백준] 5724 1 2 3 4 5 6 7 8 9 10 import sys def pinman(n): cnt=0 for i in range(1,n+1): cnt+=pow(i,2) return(cnt) while True: n=int(sys.stdin.readline()) if n==0: exit() else: print(pinman(n)) cs 2021. 1. 9.
[백준] 5704 1 2 3 4 5 6 7 8 9 10 11 12 13 14 import sys while True: tmp = [0] * 26 try : s=sys.stdin.readline() if s=="*": exit() else: for i in range(len(s)-1): if ord(s[i])!=32 : tmp[ord(s[i])-97]=1 if sum(tmp) ==26: print("Y") else: print("N") except : exit() cs 2021. 1. 9.
[백준] 5691 1 2 3 4 5 import sys while True: a,b=map(int, sys.stdin.readline().split()) if a==0 and b==0 :exit() print( min(a,b)- abs(a-b) ) cs 2021. 1. 9.
[백준] 5656 1 2 3 4 5 6 7 8 import sys cnt=1 while True: s=sys.stdin.readline() if s[2] =="E" : exit() print ("Case %d: "%cnt,end='') print( str (eval(s))[0].lower()+str (eval(s))[1:]) cnt+=1 Colored by Color Scripter cs 2021. 1. 9.
[백준] 5622 1 2 3 4 5 6 7 8 9 10 11 12 13 14 s=input() cnt=0 two="ABC" ;three="DEF";four="GHI";five="JKL";six="MNO";seven="PQRS" eight="TUV";nine="WXYZ" for i in s: if i in two : cnt+=3 if i in three: cnt += 4 if i in four: cnt += 5 if i in five: cnt += 6 if i in six: cnt += 7 if i in seven: cnt += 8 if i in eight: cnt += 9 if i in nine: cnt += 10 print(cnt) Colored by Color Scripter cs 2021. 1. 9.
[백준] 5597 1 2 3 4 5 6 tmp=[0]*31 tmp[0]=1 for i in range(28): tmp[int(input())]=1 for i in range(31): if tmp[i]==0 :print(i) cs 2021. 1. 9.
[백준] 5586 1 2 3 4 5 6 7 8 9 import sys s=sys.stdin.readline() cnt1=0 cnt2=0 for i in range(len(s)-2): if s[i]=='J' and s[i+1]=='O' and s[i+2]=='I': cnt1+=1 elif s[i] == 'I' and s[i + 1] == 'O' and s[i + 2] == 'I': cnt2 += 1 print(cnt1) print(cnt2) Colored by Color Scripter cs 2021. 1. 9.
[백준] 5576 1 2 3 4 5 6 7 8 9 10 import sys teamW=[] teamK=[] for _ in range(10): teamW.append(int(sys.stdin.readline())) for _ in range(10): teamK.append(int(sys.stdin.readline())) teamW.sort(reverse=True) teamK.sort(reverse=True) print(sum(teamW[:3]),sum(teamK[:3])) cs 2021. 1. 9.