본문 바로가기

전체 글

(257)
React)경고- react_devtools_backend.js:4012 Warning: You provided a `checked` prop to a form field without an `onChange` handler. 해당 경고가 나온 코드를 보자. 경고 표시를 잘 읽어보면 "onChange가 없이 렌더링 됐습니다."라고 나온다. onChange함수를 추가해주면 간단하게 해결된다.
프로그래머스)[1]차 다트 게임-pyhton https://school.programmers.co.kr/learn/courses/30/lessons/17682 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr import re def solution(dartResult): answer = 0 dart = re.split('([*,#,S,D,T])',dartResult) stack = [] num = 0 for i in dart: if i.isdigit(): num = int(i) elif i in ['*','#']: if i == '*': stack[-1] = stack[-1] * 2 if len(st..
백준4963)섬의 개수-python https://www.acmicpc.net/problem/4963 import sys read = sys.stdin.readline sys.setrecursionlimit(10000) def dfs(x,y,visit,arr): visit[x][y] = True dx = [0,0,1,-1,-1,-1,1,1] dy = [1,-1,0,0,-1,1,-1,1] for i in range(len(dx)): nx = dx[i] + x ny = dy[i] + y if (0
백준10815)숫자카드-pyhton https://www.acmicpc.net/problem/10815 10815번: 숫자 카드 첫째 줄에 상근이가 가지고 있는 숫자 카드의 개수 N(1 ≤ N ≤ 500,000)이 주어진다. 둘째 줄에는 숫자 카드에 적혀있는 정수가 주어진다. 숫자 카드에 적혀있는 수는 -10,000,000보다 크거나 같고, 10, www.acmicpc.net a = int(input()) arr = list(map(int,input().split())) b = int(input()) arr2 = list(map(int,input().split())) arr.sort() def b(start,end,target): mid = (start + end) // 2 if end < start: return 0 if arr[mid]..
백준1654)랜선 자르기-python https://www.acmicpc.net/problem/1654 1654번: 랜선 자르기 첫째 줄에는 오영식이 이미 가지고 있는 랜선의 개수 K, 그리고 필요한 랜선의 개수 N이 입력된다. K는 1이상 10,000이하의 정수이고, N은 1이상 1,000,000이하의 정수이다. 그리고 항상 K ≦ N 이다. 그 www.acmicpc.net n,m = map(int,input().split()) arr = [] for _ in range(n): a = int(input()) arr.append(a) start = 1 end = max(arr) while start = mid: line += i // mid if line < m: end = mid - 1 else: start = mid + 1 print(e..
백준)숫자카드-python https://www.acmicpc.net/problem/10816 이문제는 이분탐색으로 분류됐지만 사실 이분탐색을 사용하지는 않았다. 단순히 딕셔너리에 숫자와 그 개수를 담고 그대로 출력하면 된다. 굉장히 간단한 문제다. from collections import Counter a = int(input()) arr = list(map(int,input().split())) arr.sort() b = int(input()) arr2 =list(map(int,input().split())) dic = Counter(arr) for i in arr2: if i in dic: print(dic[i],end=' ') else: print(0,end=' ')
*프로그래머스)카펫-python https://school.programmers.co.kr/learn/courses/30/lessons/42842 def solution(brown, yellow): answer = [] total = brown + yellow for width in range(1,total): if total % width == 0: height = total // width if width >= height and 2*width + 2*height == brown + 4: return [width,height] return answer 처음엔 무슨 규칙으로 풀려 시도했었다. 즉 dp로 시도해보았다. brown + yellow == width * height를 발견했다. 그러나 brown + yellow 의 약수들은 ..
*프로그래머스)뒤에 있는 큰 수 찾기-python https://school.programmers.co.kr/learn/courses/30/lessons/154539 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr def solution(numbers): answer = [-1] * len(numbers) stack = [] for i in range(len(numbers)): while stack and numbers[stack[-1]] < numbers[i]: answer[stack.pop()] = numbers[i] stack.append(i) return answer 이 문제는 검색해서 푼 문제이다..
프로그래머스)두 큐 합 같게 만들기-pyhton https://school.programmers.co.kr/learn/courses/30/lessons/118667 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 1차원적으로 보자면 매우 간단한 문제이다. 큐1과 큐2가 같게 만들 떄까지 큰 것에서 작은 것으로 pop,left를 반복해주면 된다. 예를들어 큐1의 합이 15, 큐2의 합이 16이라면 큐2에서 popleft, queue1.append()를하면 된다. 다만 어디까지 for문 또는 while문을 돌려야하나 그것이 문제였다. 대충 찍으면 답이 나올 것 같지만 정확한 이해가 필요했기에 검색을 했다. ..
프로그래머스)수식 최대화-pyhton https://school.programmers.co.kr/learn/courses/30/lessons/67257 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제를 이해하기엔 쉬웠지만 이를 구현하는데 애를 먹었다. def solution(expression): answer = 0 m = 0 arr = ['*','-','+'] for i in range(0,3): calculate = arr[i] summ = [] arr2 = ['*','-','+'] arr3 = ['*','-','+'] arr2.remove(calculate) arr3.remove(c..
프로그래머스) 메뉴 리뉴얼-python https://school.programmers.co.kr/learn/courses/30/lessons/72411 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr from itertools import combinations def solution(orders, course): answer = [] dic = {} for i in range(len(orders)): for j in range(len(course)): if len(orders[i]) >= course[j]: arr = list(orders[i]) for k in combinations(arr..
백준) 거스름돈-python https://www.acmicpc.net/problem/5585 5585번: 거스름돈 타로는 자주 JOI잡화점에서 물건을 산다. JOI잡화점에는 잔돈으로 500엔, 100엔, 50엔, 10엔, 5엔, 1엔이 충분히 있고, 언제나 거스름돈 개수가 가장 적게 잔돈을 준다. 타로가 JOI잡화점에서 물건을 사 www.acmicpc.net a = int(input()) a = 1000 - a answer = 0 while a > 0: if a >= 500: answer += a // 500 a = a % 500 elif a >= 100: answer += a // 100 a = a % 100 elif a >= 50: answer += a // 50 a = a % 50 elif a >= 10: answer += ..
백준) 잃어버린 괄호-python https://www.acmicpc.net/problem/1541 1541번: 잃어버린 괄호 첫째 줄에 식이 주어진다. 식은 ‘0’~‘9’, ‘+’, 그리고 ‘-’만으로 이루어져 있고, 가장 처음과 마지막 문자는 숫자이다. 그리고 연속해서 두 개 이상의 연산자가 나타나지 않고, 5자리보다 www.acmicpc.net a = input().split('-') num = [] for i in a: cnt = 0 s = i.split('+') for j in s: cnt += int(j) num.append(cnt) n = num[0] for i in range(1, len(num)): n -= num[i] print(n) 사실 이문제에서 시간이 좀 오래 걸렸다. 가장먼저 괄호라는 기능을 어떻게 구현할 것인가..
프로그래머스) 소수 찾기-python https://school.programmers.co.kr/learn/courses/30/lessons/42839 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr from itertools import permutations def isTrue(n): for i in range(2,n): if n % i == 0: return False return True def solution(numbers): answer = 0 arr = list(numbers) check = [] for i in range(1,len(numbers)+1): for j in perm..
프로그래머스) 2 x n 타일링-python https://school.programmers.co.kr/learn/courses/30/lessons/12900 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 사실 문제를 어떻게 풀어야할지 감도 잡히지 않았다. 그리디, DFS, BFS 스택,큐, 정렬... 그리고 경우의수를 생각했을 때 절대 내가 알고있는 알고리즘으로 풀 수 없다고 생각했고 검색을 해보았다. def solution(n): answer = 0 arr = [0] * (n + 1) arr[1] = 1 arr[2] = 2 for i in range(3,n+1): arr[i] = (arr[i-1..