본문 바로가기

파이썬

(70)
[ BOJ ] 13458 시험 감독 https://www.acmicpc.net/problem/13458 13458번: 시험 감독 첫째 줄에 시험장의 개수 N(1 ≤ N ≤ 1,000,000)이 주어진다. 둘째 줄에는 각 시험장에 있는 응시자의 수 Ai (1 ≤ Ai ≤ 1,000,000)가 주어진다. 셋째 줄에는 B와 C가 주어진다. (1 ≤ B, C ≤ 1,000,000) www.acmicpc.net 난 바보라네.. 브론즈 문제도 25분 걸리는 바보. import math n = int(input()) a = list(map(int, input().split())) b, c = map(int, input().split()) answer = n for num in a: num -= b if num > 0: num = math.ceil(nu..
[ BOJ ] 스타트와 링크 / 제출 1 / from itertools import combinations n = int(input()) s = [list(map(int,input().split())) for _ in range(n)] teamA = list(combinations(range(n), n//2)) teamB = [] for a in teamA: b = [] for i in range(n): if i not in a: b.append(i) teamB.append(tuple(b)) diff = 100 for a, b in zip(teamA, teamB): levA = 0 levB = 0 playerA = list(combinations(a, 2)) playerB = list(combinations(b, 2)) for i,..
[ BOJ ] 구슬 탈출 2 / 구현 1 / n, m = map(int, input().split()) board = [list(input()) for _ in range(n)] for i in range(n): for j in range(m): if board[i][j] == 'R': red = [i, j] elif board[i][j] == 'B': blue = [i, j] elif board[i][j] == 'O': hole = [i, j] movePossible = True count = 0 dx = [-1, 1, 0, 0] dy = [0, 0, -1, 1] def roll(i, ball): nx = ball[0] + dx[i] ny = ball[1] + dy[i] if board[nx][ny] != '#': return [..
[ 프로그래머스 ] 짝지어 제거하기 / 제출 1 / def solution(s): answer = -1 s = list(s) strStack = [] for char in s: if not strStack: strStack.append(char) else: if strStack[-1] == char: strStack.pop() return int(not bool((strStack))) 채점 결과 정확성: 59.7 효율성: 39.8 합계: 99.5 / 100.0 바로 구현 방식이 떠오르고 예제도 쉽게 풀려 바로 제출했는데 정확성의 테스트 케이스(13)를 하나 통과하지 못했습니다. 자만이었던 것 같습니다. LV1을 풀고 와서 이 문제도 들이대면 풀릴 줄 알았던건 지 .. 수정해보도록 하겠습니다. / 제출 2 / def solution(s): ..
[ 프로그래머스 ] 서울에서 김서방 찾기 / 제출 1 / def solution(seoul): kimLocation = seoul.index('Kim') return '김서방은 ' + str(kimLocation) + '에 있다' 채점 결과 정확성: 100.0 합계: 100.0 / 100.0 프로그래머스 연습 문제로 제공되는 LV1문제는 원래 간단한 것 같습니다. 기업 기출이었던 같은 난이도 문제와는 결이 확실히 다릅니다. 다만, 계속 주의해야할 것은 자바스크립트와 파이썬을 오가면서 사용하다 보니 서로의 문법이나 메서드 등이 헷갈릴 때가 있습니다. 이번에 그런 실수를 했는데요. 자바스크립트의 indexOf를 사용해 특정 단어의 인덱스 값을 받으려고 해서 에러가 떴습니다. AttributeError: 'list' object has no attr..
[ 프로그래머스 ] 문자열 내 p와 y의 개수 / 제출 1 / def solution(s): pCount = 0 yCount = 0 for char in s: if char == 'p' or char == 'P': pCount += 1 elif char == 'y' or char == 'Y': yCount += 1 if pCount == 0 and yCount == 0: return True elif pCount == yCount: return True else: return False 채점 결과 정확성: 100.0 합계: 100.0 / 100.0 정말 간단한 문제였습니다. 문제 이해하는 데에 별 다른 시간이 소요되지 않는 문제였던 것 같습니다. 대신 어떻게 다양한 방식으로 언어를 활용해볼 지(문법을 다양하게 적용해볼 지) 생각해 볼 수 있을 것 같..
[ 프로그래머스 ] 문자열 내 마음대로 정렬하기 / 제출 1 / ''' 문제 인풋-아웃풋: n이 주어졌을 때, 인덱스 n기준으로 각 단어를 정렬 주요 예외: ! 해당 인덱스 자리 문자가 같으면 ! 단어 전체가 사전순으로 앞선게 앞으로 # 1. string을 돌며, [해당 인덱스 자리 문자, 해당 단어] 원소를 리스트에 넣기 # 2. 1의 리스트를 [0]기준 정렬, [1]길이 기준 정렬 # 3. 2처리 끝난 리스트를 [0] 순서대로 뽑아 answer에 넣기 ## strings: 100 * 50 이므로 O(n), O(nLogn), O(n) 무리 없다고 판단 ''' def solution(strings, n): answer = [] charAndWordList = getCharWordList(strings, n); print(charAndWordList) ..
[ 프로그래머스 ] [1차] 다트게임 / 제출 1 / def solution(dartResult): darts = list(dartResult.strip()) result = [] num = 'ss' for dart in darts: print(num, dart, result) # 숫자 저장 if dart.isdigit(): if num == 1 and dart == '0': print('10') num = 10 if num != 'ss': result.append(num) print(result) num = -1 num = int(dart) # S,D,T에 따라 곱해주기 elif dart == 'S': num = num ** 1 elif dart == 'D': num = num ** 2 elif dart == 'T': num = num *..
[ 백준 / BOJ ] 나3곱2 / 제출 1 / n = int(input()) B = list(map(int, input().split())) # 나3, 곱2 => 곱3, 나2 해서 값 나오면 해당 숫자의 이전 값, 둘이 붙여 # 만약 둘 다 안 되면 그게 첫 번째 값 order = [] for num in B: mulThree = num * 3 if num % 2 == 0: divTwo = num // 2 else: divTwo = 0 if divTwo in B: order.append([divTwo, num]) continue elif mulThree in B: order.append([mulThree, num]) continue else: order.append([0, num]) result = [] start = 0 next =..
[ 백준 / BOJ ] 2504 괄호의 값 / 첫 구현 / from collections import deque import sys bracket = list(sys.stdin.readline().strip()) calc = [] so = 0 dae = 0 temp = deque([]) while bracket: now = bracket.popleft() if now == '(': calc.append(2) so += 1 next = bracket.popleft() if next != ')': # 안에 뭐 있으면 calc.append('x') calc.append('(') while so > 0: temp.append(next) if next == elif now == '[': calc.append(3) dae += 1 if bracket[0] ..