백준_단계별로 풀어보기_20단계_심화 2

■ 백준 1037 약수_브론즈 1

- 1과 N 빼고 다 주어졌을 때 N을 찾는 문제

n = int(input())
n_li = sorted(list(map(int, input().split())))
print(n_li[0]*n_li[-1])

 

■ 백준 25192 인사성 밝은 곰곰이_실버 4

- 👋🐻

# [Psuedo code]
# 엔터를 받고 난 뒤에 이름들은 곰곰티콘을 받음
# 엔터를 받을 때 새로운 딕셔너리 생성?
# import sys
# gomgom = {}
# for i in range(int(input())):
#     name = sys.stdin.readline().rstrip()
#     if name in gomgom:
#         if name != "ENTER" and gomgom['ENTER'] < 2: continue
#         else:
#             gomgom[name] += 1
#             if gomgom['ENTER'] < gomgom[name]:
#                 gomgom[name] -= 1
#     else: gomgom[name] = 1
# del gomgom["ENTER"]
# print(sum(gomgom.values()))

# 수정코드: 수도코드를 썼던 대로 엔터를 받을 때 초기화를 시켰다.
import sys
gomgom = set()
cnt = 0
for i in range(int(input())):
    name = sys.stdin.readline().rstrip()
    if name == "ENTER":
        gomgom.clear() #gomgom = set()
        continue
    if name in gomgom:
        continue
    else:
        cnt += 1
        gomgom[name] = 1
print(cnt)

 

■ 백준 26069 붙임성 좋은 총총이_실버 4

- 🌈🤸

import sys
dance = set(["ChongChong"])
meet = sys.stdin.readlines()[1:]
for x in meet:
    a, b = x.split()
    if a in dance:
        dance.add(b)
    elif b in dance:
        dance.add(a)
print(len(dance))

 

■ 백준 2108 통계학_실버 3

- 다양한 통곗값을 구하는 문제

import sys
input = sys.stdin.readline
n = int(input())
arr = []
d = dict()
ans = []
for _ in range(n):
    x = int(input())
    arr.append(x)
    if x in d: d[x]+=1
    else: d[x]=1
ans.append(str(round(sum(arr) / n + 1e-4))) # avg
arr.sort()
ans.append(str(arr[n//2])) # middle
d = sorted(d.items(), key=lambda item: item[1], reverse=True)
many = []
for i in range(len(d)):
    if d[0][1] == d[i][1]:
        many.append(d[i][0])
many.sort()
ans.append(str(many[1] if len(many) > 1 else many[0])) # second mode
ans.append(str(arr[-1]-arr[0])) # range
sys.stdout.write("\n".join(ans))

 

■ 백준 20920 영단어 암기는 괴로워_실버 3

- 복잡한 기준으로 정렬하는 문제

- 팁: 정렬 시 람다 함수로 요소에 (-)를 붙여주면 reverse가 된다.

# import sys
# input = sys.stdin.readline
# d = dict()
# n, m = map(int, input().split())
# for _ in range(n):
#     word = input().rstrip()
#     if len(word) >= m:
#         if word in d:
#             d[word] += 1
#         else:
#             d[word] = 1
# d = sorted(d.items())
# d = sorted(d, key=lambda item: -len(item[0]))
# d = dict(sorted(d, key=lambda item: -item[1]))
# sys.stdout.write("\n".join(d))

# 고수코드: collections 라이브러리의 Counter 메서드를 사용했다.
from collections import Counter
def main():
    S = open(0).read().split()
    m = int(S[1])
    counter = Counter(word for word in S[2:] if len(word) >= m)
    words = list(counter)
    words.sort()
    words.sort(key=len, reverse=True)
    words.sort(key=counter.get, reverse=True)
    print("\n".join(words))

if __name__ == "__main__":
    main()