[파이썬] 백준 - 18단계 심화2
약수 (1037)
N = int(input())
a = list(map(int,input().split()))
a.sort()
print(a[0]*a[-1])
인사성 밝은 곰곰이 (25192)
N = int(input())
count = 0
table = {'ENTER':0}
for i in range(N):
a = input()
if a == 'ENTER':
table = {'ENTER':0}
else :
if a not in table :
table[a] = 1
if table[a] == 1 :
table[a] += 1
count += 1
print(count)
집합도 시간복잡도가 O(1)이네요. 집합으로 푸는게 좀 더 깔끔했을듯
붙임성 좋은 총총이 (26069)
N = int(input())
temp = set({})
for i in range(N):
a,b = input().split()
if a == 'ChongChong' or b == 'ChongChong' :
temp.add(a)
temp.add(b)
continue
else :
if a in temp :
temp.add(b)
elif b in temp :
temp.add(a)
temp_list = list(temp)
print(len(temp_list))
통계학 (2108)
import sys
N = int(input())
temp = {}
count = 0
for i in range(N):
a = int(sys.stdin.readline())
count += a
if a in temp :
temp[a] += 1
else :
temp[a] = 1
print(round(count/N)) # 평균
midean = list(temp.items())
midean.sort()
count = 0
for i in midean: # 중앙값
count += i[1]
if count > int(N/2) :
print(i[0])
break
mode = [key for key, value in temp.items() if value == max(temp.values())]
mode.sort()
if len(mode) > 1 : # 최빈값
print(mode[1])
elif len(mode) == 1:
print(mode[0])
print(max(temp.keys())-min(temp.keys())) # 범위
영단어 암기는 괴로워 (20920)
import sys
N,M = map(int,input().split())
table = {}
length = []
for i in range(N) :
word = sys.stdin.readline().strip()
if len(word) < M :
continue
if word in table :
table[word] += 1
else :
length.append(len(word))
table[word] = 1
temp = list(zip(table.items(),length))
answer = sorted(temp,key = lambda x:(-x[0][1],-x[1],x[0][0]))
for i in answer:
print(i[0][0])
strip() 안써서 10번넘게틀림 ㅋㅋㅋㅋㅋㅋ
드래그 해서 공백 있는지 잘 체크하기..
'Algorithm > etc' 카테고리의 다른 글
[파이썬] 백준 - 15단계 약수,배수와 소수2 (0) | 2023.04.28 |
---|---|
[파이썬] 백준 - 19단계 스택 (0) | 2023.04.22 |
[파이썬] 백준 - 실랜디 (0) | 2023.04.20 |
[파이썬] 백준 - 17단계 조합론 (0) | 2023.04.19 |
[파이썬] 백준 - 14단계 집합과 맵 (0) | 2023.04.18 |
[파이썬] 백준 - 13단계 정렬 (0) | 2023.04.17 |
[파이썬] 백준 - 10단계 기하: 직사각형과 삼각형 (0) | 2023.04.08 |
댓글