본문 바로가기

반응형

문제풀이/백준

(3)
문제 11723 - 집합 - 파이썬 개선해나갔던 사항을 아래와 같다. # list, set 사용 구분 # 저장시 str, int 사용 구분 # input 대신 readline 사용 # pypy는 시간은 적지만 메모리를 많이 소모하여 python으로 변경 코드는 아래와 같다. import sys S = set() cnt = int(sys.stdin.readline().strip()) for _ in range(cnt): given = sys.stdin.readline().strip().split() if given[0] == 'all': S = set([i for i in range(1, 21)]) continue elif given[0] == 'empty': S = set() continue else: cmd, x = given[0], i..
백준 - 단어 정렬 1181번 https://www.acmicpc.net/problem/1181 1181번: 단어 정렬 첫째 줄에 단어의 개수 N이 주어진다. (1 ≤ N ≤ 20,000) 둘째 줄부터 N개의 줄에 걸쳐 알파벳 소문자로 이루어진 단어가 한 줄에 하나씩 주어진다. 주어지는 문자열의 길이는 50을 넘지 않는다. www.acmicpc.net ** 내 풀이 from sys import stdin cnt = int(stdin.readline()) hh = [] for _ in range(cnt): oneword = stdin.readline().rstrip() if oneword not in hh: hh.append(oneword) hh.sort(key=lambda x:(len(x), x)) for i in hh: print(..
5022번 - 전화번호 목록 **문제 https://www.acmicpc.net/problem/5052 5052번: 전화번호 목록 첫째 줄에 테스트 케이스의 개수 t가 주어진다. (1 ≤ t ≤ 50) 각 테스트 케이스의 첫째 줄에는 전화번호의 수 n이 주어진다. (1 ≤ n ≤ 10000) 다음 n개의 줄에는 목록에 포함되어 있는 전화번호가 www.acmicpc.net **오류 코드 (Time Limit) from sys import stdin numTestCase = int(stdin.readline().strip()) tot = [] for _ in range(numTestCase): cntPhone = int(stdin.readline().strip()) phoneNum = [] for _ in range(cntPhone):..

반응형