백준 / 25206번 / 너의 평점은 / python 파이썬
·
코딩테스트/백준 (python)
문제 : https://www.acmicpc.net/problem/25206  코드 score = {'A+':4.5, 'A0':4.0, 'B+':3.5, 'B0':3.0, 'C+':2.5, 'C0':2.0, 'D+':1.5, 'D0':1.0, 'F':0}count = 0result = 0for i in range(20): inp = input().split(' ') if inp[2] != 'P': result += float(inp[1]) * score[inp[2]] count += float(inp[1])print('%.6f' %(result / count))    알게된 것
백준 / 14425번 / 문자열 집합 / python 파이썬
·
코딩테스트/백준 (python)
문제 : https://www.acmicpc.net/problem/14425 코드 n, m = map(int, input().split())n_string = set()for i in range(n): n_string.add(input())count = 0for i in range(m): string = input() if string in n_string: count += 1print(count) 알게된 것문제에서 집합 S에 같은 문자열이 여러 번 주어지는 경우가 없다고 해서 리스트를 이용해서 풀었는데 해당 문자열이 S에 있는지 확인할 때 사용하는 in은 자료구조에 따라 시간 복잡도가 다르다. set()을 이용하면 더욱 빠르게 풀 수 있다. set은 hash table 구조..
백준 / 2566번 / 최댓값 / python 파이썬
·
코딩테스트/백준 (python)
문제 : https://www.acmicpc.net/problem/2566  코드import sysinput = sys.stdin.readlineans = -1for i in range(9): row = list(map(int, input().split())) max_num = max(row) if ans
백준 / 1157번 / 단어 공부 / python 파이썬
·
코딩테스트/백준 (python)
문제 : https://www.acmicpc.net/problem/1157  코드 import sysfrom collections import Counterword = sys.stdin.readline().strip()word = word.upper()count = Counter(word)m = [k for k,v in count.items() if max(count.values()) == v]if len(m) == 1: print("".join(m))else: print('?')Counter를 사용해 딕셔너리로 푼 코드이다. 다른 풀이word = input().upper()word_list = list(set(word))cnt = []for i in word_list: count = wor..
백준 / 15552번 / 빠른 A+B / python 파이썬
·
코딩테스트/백준 (python)
문제 : https://www.acmicpc.net/problem/15552 코드 import sysnum = int(sys.stdin.readline())for _ in range(num): a, b = map(int, sys.stdin.readline().split()) print(a + b)
백준 / 1181번 / 단어 정렬 / python 파이썬
·
코딩테스트/백준 (python)
문제 : https://www.acmicpc.net/problem/1181  코드 (오답)n = int(input())s = []for i in range(n): s.append(input())s.sort(key = len)for i in s: print(i) 중복된 단어는 하나만 남기고 제거한다는 조건을 보지 못하였고, input()을 사용해 속도가 느렸다. 재시도 (정답)import sysn = int(sys.stdin.readline())s = []for i in range(n): s.append(sys.stdin.readline().strip())set_s = set(s)s = list(set_s)s.sort()s.sort(key = len)for i in s: print(i..
백준 / 11718번 / 그대로 출력하기 / python 파이썬
·
코딩테스트/백준 (python)
문제 : https://www.acmicpc.net/problem/11718  코드 import sysword = sys.stdin.readlines()for w in word: print(w.rstrip())readlines()를 사용해 여러 입력을 한 번에 받는다. 각 문장 마지막에 개행문자 \n이 함께 저장되므로 rstrip을 사용해 개행문자를 제거해준다.
백준 / 5622번 / 다이얼 / python 파이썬
·
코딩테스트/백준 (python)
문제 : https://www.acmicpc.net/problem/5622  코드 answer = 0num = ['', '', '', 'ABC', 'DEF', 'GHI', 'JKL', 'MNO', 'PQRS', 'TUV', 'WXYZ']word = input()for w in word: for i, n in enumerate(num): if w in n: answer += iprint(answer)