python-algorithm1422 백준 13225 Divisors 1 2 3 4 5 6 7 def divisiors(num): ans=[] for i in range(1,num+1): if num%i==0: ans.append(i) print(num,len(ans)) for _ in range(int(input())): divisiors(int(input())) cs 2021. 11. 19. 백준 9288 More Dice 1 2 3 4 5 6 7 n=int(input()) for i in range(n): number=int(input()) print("Case %d:"%(i+1)) for j in range(1,number//2+1): if j 2021. 11. 19. 백준 6975 Deficient, Perfect, and Abundant 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 import math n=int(input()) for i in range(n): if i !=0 : print() tmp=1 number=int(input()) cnt=math.ceil(math.sqrt(number)) if number==1: print ("1 is a deficient number.") else: for j in range(2,cnt): if number%j==0: tmp+=j+ number//j if tmpnumber: print("%d is an abundant number."%number) cs 약수의 합으로 분류하는 문제인데 LIne 7같이 한 이유는 1부터 입력받은 숫자까지 전부 반복할 필요 없.. 2021. 11. 12. 2167 2차원 배열의 합 1 2 3 4 5 6 7 8 9 10 11 12 n,m=map(int, (input().split())) list_1 = [] for i in range(n): list_1.append(list(map(int, input().split()))) k=int(input()) for i in range(k): a,b,c,d=map(int,input().split()) ans=0 for j in range(a-1,c): for k in range(b-1,d): ans+=list_1[j][k] print(ans) Colored by Color Scripter cs 2021. 11. 12. 백준 2738 행렬 덧셈 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 n,m=map(int, (input().split())) list_1 = [] list_2 = [] for i in range(n): list_1.append(list(map(int, input().split()))) for i in range(n): list_2.append(list(map(int, input().split()))) ans=[] for i in range(n): tmp = [] for j in range(m): tmp.append(list_1[i][j]+list_2[i][j]) ans.append(tmp) for i in ans: print(*i) Colored by Color Scripter cs 2021. 11. 12. Hacker rank Print the Elements of a Linked List 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 #!/bin/python3 import math import os import random import re import sys class SinglyLinkedListNode: def __init__(self, node_data): self.data = node_data self.next = None class SinglyLinkedList: def __init__(self): self.head = None self... 2021. 11. 12. 백준 2745 진법 변환 1 2 3 4 5 6 7 8 #print(ord('A')-55) s=input().split() n,b=s[0],int(s[1]) ans=0 for i in range(len(n)): if n[len(n)-i-1].isupper(): ans+=(ord(n[len(n)-i-1])-55)*pow(b,i) else : ans+=int(n[len(n)-i-1])*pow(b,i) print(ans) Colored by Color Scripter cs 2021. 11. 2. 백준 2495 연속구간 1 2 3 4 5 6 7 8 9 10 11 12 for _ in range(3): s = str(input()) mymax = 1 cnt = 1 for i in range(1,len(s)): if s[i]==s[i-1]: cnt+=1 else: mymax=max(cnt,mymax) cnt=1 mymax = max(cnt, mymax) print(mymax) cs 2021. 11. 2. 백준 1371 가장 많은 글자 1 2 3 4 5 6 7 import sys ans=[0]*26 s=sys.stdin.read() for i in s: if i.islower(): ans[ord(i)-97]+=1 for i in range(len(ans)): if ans[i]==max(ans): print(chr(97+i),end='') cs ord와 chr함수를 이용해 아스키코드값으로 문자열 처리하는 방식입니다 2021. 11. 2. 백준 20944 팰린드롬 척화비 1 2 3 4 5 n=int(input()) if n%2==0: print('a'*n) else: if n==1: print('a') else: print('a'*(n//2)+'b'+'a'*(n//2)) cs 2021. 11. 2. 백준 20540 연길이의 이상형 1 2 3 4 5 6 7 8 9 10 11 pythos=input() ans='' if s[0]=='E': ans+="I" else: ans+='E' if s[1]=='S': ans+="N" else: ans+='S' if s[2]=='T': ans+="F" else: ans+='T' if s[3]=='J': ans+="P" else: ans+='J' print(ans) cs 2021. 11. 2. Hacker rank Find the Median 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 #!/bin/python3 import math import os import random import re import sys # # Complete the 'findMedian' function below. # # The function is expected to return an INTEGER. # The function accepts INTEGER_ARRAY arr as parameter. # def findMedian(arr): # Write your code here arr=sorted(arr) cnt=len(arr) return ar.. 2021. 10. 28. 이전 1 ··· 63 64 65 66 67 68 69 ··· 119 다음