Study/Algorithm
-
백준 10828 "스택" 파이썬 문제풀이Study/Algorithm 2024. 3. 8. 19:15
지난학기 수강했던 자료구조 강의에서 배운 내용을 이용하여 코드를 작성해보았다 stack = [] high = -1 def push(num) : global high stack.append(num) high += 1 def top() : if len(stack) == 0 : print(-1) else : print(stack[high]) def userDefPop() : global high if high == -1 : print(-1) else : print(stack.pop()) high -= 1 n = int(input()) for _ in range(n): command = input() if "push" in command : command = command.split() push(command[..
-
코드 실행 시간 단축 "ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);"Study/Algorithm 2024. 1. 1. 22:00
백준 10871번 문제를 풀었는데, 시간이 4ms로 나왔다. 다른 사람들의 시간을 보니 4ms도 있었지만 0ms가 많았다. 4ms가 걸린 코드는 아래와 같다. #include using namespace std; int main() { int n, x, i = 0; cin >> n >> x; int a[n]; int answer[n]; for (i = 0; i > a[i]; } for (i = 0; i < n; i++) { if (a[i] < x) cout