분류 전체보기(104)
-
백준 에러 난 이유 궁금할 때
leetcode 풀 때는 에러 메시지랑 test case까지 보여줘서 문제점이 뭔지 바로 알 수 있었는데 백준은 "런타임 에러" 이렇게만 알려주고 아무것도 알려주지 않는다 ㅜㅜ 그럴때, https://ideone.com/ Ideone.com Ideone is something more than a pastebin; it's an online compiler and debugging tool which allows to compile and run code online in more than 40 programming languages. ideone.com 여기서 해당 코드를 입력하고 언러를 선택한 뒤 돌려보면, 무엇이 문제인지 알 수 있다!
2021.02.10 -
BOJ 10250. ACM 호텔 (Python)
BOJ 10250. ACM 호텔 https://www.acmicpc.net/problem/10250 10250번: ACM 호텔 프로그램은 표준 입력에서 입력 데이터를 받는다. 프로그램의 입력은 T 개의 테스트 데이터로 이루어져 있는데 T 는 입력의 맨 첫 줄에 주어진다. 각 테스트 데이터는 한 행으로서 H, W, N, 세 정수 www.acmicpc.net Logic 예를 들면 102 호 방보다는 301 호 방을 더 선호하는데, 102 호는 거리 2 만큼 걸어야 하지만 301 호는 거리 1 만큼만 걸으면 되기 때문이다. 같은 이유로 102 호보다 2101 호를 더 선호한다. 엘리베이터로 이동하는 거리는 무시한다고 했다. 그러면 방이 배정되는 순서는 101, 201, 301, 401,,, 다음은 102, 2..
2021.02.10 -
BOJ 1085. 직사각형에서 탈출 (Python)
BOJ 1085. 직사각형에서 탈출 1085번: 직사각형에서 탈출 한수는 지금 (x, y)에 있다. 직사각형의 왼쪽 아래 꼭짓점은 (0, 0)에 있고, 오른쪽 위 꼭짓점은 (w, h)에 있다. 직사각형의 경계선까지 가는 거리의 최솟값을 구하는 프로그램을 작성하시오. www.acmicpc.net Solution x, y, w, h = map(int, input().split()) print(min(w-x, h-y, x, y)) import sys x, y, w, h = map(int, sys.stdin.readline().split()) print(min(w-x, h-y, x, y)) 문득 sys.stdin.readline()을 사용하면 input()보다 더 빠른 속도를 낼 수 있다고 한게 생각나서 공부하..
2021.02.09 -
[Python] input()과 sys.stdin
sys.stdin 알고리즘 문제를 풀 때, 파이썬의 input()은 실행시간이 느려서 자주 시간초과가 난다. 이럴때 sys모듈의 stdin을 사용하면 더 빠르게 input이 가능하다.. 고 하는데, 나는 input()과 sys.stdin의 차이점을 알고싶었다. input() vs sys.stdin input() input() 파이썬의 내장함수이고, 공식 문서의 'Built in function'에가면 해당 내용을 읽어 볼 수 있다. input()에 대한 파이썬 공식 문서 If the prompt argument is present, it is written to standard output without a trailing newline. The function then reads a line from ..
2021.02.09 -
Leetcode 104. Maximum Depth of Binary Tree
Leetcode 104. Maximum Depth of Binary Tree https://leetcode.com/problems/maximum-depth-of-binary-tree/ Maximum Depth of Binary Tree - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com Logic BFS구현(Python) 처음엔 보통 bfs 처럼 while문을 돌고 depth를 하나씩 늘려줬는데 while queue: depth += 1 cur = queue.po..
2021.02.08 -
BOJ 10818. 숫자의 합(Python)
BOJ 10818. 숫자의 합(Python) https://www.acmicpc.net/problem/11720 11720번: 숫자의 합 첫째 줄에 숫자의 개수 N (1 ≤ N ≤ 100)이 주어진다. 둘째 줄에 숫자 N개가 공백없이 주어진다. www.acmicpc.net Solution N = int(input()) nums = list(map(int,input().split())) print(min(nums), end=" ") print(max(nums))
2021.02.07