목록분류 전체보기 (317)
지나가던 개발자

n = int(input()) if n == 1: print(input()) else: files = [] for i in range(n): files.append(input()) for i in range(len(files[0])): letter = files[0][i] printed = False for j in range(1, len(files)): if files[j][i] == letter: continue print("?", end="") printed = True break if not printed: print(letter, end="")

nums = [] for i in range(5): nums.append(int(input())) print(int(sum(nums)/len(nums))) print(sorted(nums)[len(nums)//2]) 4번줄에서 평균이 소수로 나오면 어떻게 할까 하는 생각을 했는데, 문제를 다시 읽어보니 주어지는 자연수는 100보다 작은 10의 배수였다. 이게 왜 브론즈II?

n, s = input().split() nicks = [] chats = [] isNick = False for i in range(int(n)): nick, chat = input().split() if isNick: continue if nick == s: isNick = True nicks.append(nick) chats.append(chat) answer = chats[nicks.index(s)] ans = 0 for i in chats: if i == answer: ans += 1 print(ans-1)

while True: year = int(input()) if year == 0: break if year % 4 == 0 and year >= 1896: if 1914

n = int(input()) s = input() for i in ["J", "O", "I"]: print(i*s.count(i), end="") 정렬... 이라기보다는 "J", "O", "I"로 구성된 S를 입력받아서 S에 포함된 "J", "O", "I"의 개수를 세 준 뒤, "J", "O", "I" 순서대로 각각의 개수만큼 출력해 주었다.

from collections import Counter while True: players = [] for i in range(int(input())): d = input().split() players.append([int(d[0]), d[2]]) if players == []: break players.sort(key=lambda x:x[0]) print(Counter([x[0] for x in players if x[1] == 'Gold']).most_common(1)[0][0], Counter([x[0] for x in players]).most_common(1)[0][0]) 파이썬에서 리스트의 최빈값을 구하기 위해서는 from collections import Counter를 해준 후 Coun..

s = input().split(" = ") if eval(s[0]) == int(s[1]): print("YES") else: print("NO")

n = int(input()) A = [False, False] + [True] * 7368788 Primes = [] for i in range(2, 7368788): if A[i]: Primes.append(i) for j in range(i+i, 7368788, i): A[j] = False print(Primes[n-1]) 에라토스테네스의 체 알고리즘을 사용했다. (덕분에 메모리가 145980KB...) 50만번째 소수는 7368788이다.