colab에서 파이썬 셀을 실행할 때, 간혹 pip install앞에 !이 있을때도 있고 %이 있을때도 있다.차이점이 뭔지 알아보자..! 결론부터 말하자면, 두 방식 모두 python 환경에서 패키지를 설치하는 명령어지만 실행방식이 다르다. !pip install!(느낌표)는 주피터 노트북에서 Shell 명령어를 실행할 때 사용된다.즉, python 인터프리터가 아니라 OS의 터미널/커맨드라인에서 실행하는 방식이다.일반적으로 터미널에서 실행하는 `pip install` 명령어와 동일한 동작을 한다.사용가능 환경: Jupyter Notebook, Colab, 일반 파이썬 스크립트 %pip install %pip 는 IPython(interactive python) 매직 명령어로, 주피터 노트북 및 IPyt..

1. homebrew를 사용해 설치한다. 터미널 창에서 다음 명령어를 입력한다.$ brew install python 2. python3 말고 python으로 명령어 가능하도록 설정하기vi ~/.zshrc .zshrc 맨 하단에 아래 내용을 추가한다.alias python="python3"esc키 + ":wq"를 치면 저장하고 나갈수있다. source 명령어를 통해 변경사항을 저장한다.$ source ~/.zshrc
![[백준 알고리즘] 10816번 숫자 카드 2 (Python)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FbhuMSj%2FbtqDTGwRA0I%2FPgKubcmDH9nYBcG0uaf8E1%2Fimg.png)
import sys N = int(sys.stdin.readline()) N_list = list(map(int, sys.stdin.readline().split())) N_list.sort() M = int(sys.stdin.readline()) M_list = list(map(int, sys.stdin.readline().split())) hashmap = {} for n in N_list: if n in hashmap: hashmap[n] += 1 else: hashmap[n] = 1 print(" ".join(str(hashmap[m]) if m in hashmap else '0' for m in M_list)) ▼링크 https://www.acmicpc.net/problem/10816 10816..
![[백준 알고리즘] 1966번 프린터 큐 (Python)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FbCbOV8%2FbtqDQuisTqu%2FAqzfdXCruNKDW0UkznU7LK%2Fimg.png)
import collections import sys test = int(sys.stdin.readline()) for _ in range(test): cnt = 0 n, m = map(int, sys.stdin.readline().split()) priority = collections.deque(map(int, sys.stdin.readline().split())) if len(priority) == 1: print(1) else: while True: index = priority.index(max(priority)) for _ in range(index): a = priority.popleft() priority.append(a) if m >= 1: m -= 1 else: m = len(prior..
![[백준 알고리즘] 11866번 요세푸스 문제 0 (Python)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2Fbxt6xb%2FbtqDO1arEHL%2FBFkS5gwOBxmDL5EgdEOT60%2Fimg.png)
import collections n, k = map(int, input().split()) result = [] queue = collections.deque([i for i in range(1, n + 1)]) while len(queue) > 0: for _ in range(k): if _ == k - 1: num = queue.popleft() result.append(num) else: num = queue.popleft() queue.append(num) print("") ▼링크 https://www.acmicpc.net/problem/11866 11866번: 요세푸스 문제 0 첫째 줄에 N과 K가 빈 칸을 사이에 두고 순서대로 주어진다. (1 ≤ K ≤ N ≤ 1,000) www.acmicp..
![[백준 알고리즘] 2164번 카드2 (Python)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FbD5fnG%2FbtqDRxFrrMH%2FLAz20YvmgyVbFvwMOXmm30%2Fimg.png)
import sys import collections n = int(sys.stdin.readline()) queue = [] queue = collections.deque([i for i in range(1, n+1)]) while len(queue) > 1: queue.popleft() num = queue.popleft() queue.append(num) print(queue[0]) 그냥 리스트 선언을 하여 큐를 만들면 시간초과가 된다. collection.deque를 써주어 해결하였다. ▼ 링크 https://www.acmicpc.net/problem/2164 2164번: 카드2 N장의 카드가 있다. 각각의 카드는 차례로 1부터 N까지의 번호가 붙어 있으며, 1번 카드가 제일 위에, N번 카드가 ..
![[백준 알고리즘] 2748번 피보나치 수 2 (Python)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2Fln1U8%2FbtqDOkOtyyC%2F1yRHOapfa4cRRf39vhKrv0%2Fimg.png)
n = int(input()) fibo_array = [0 for _ in range(n+1)] fibo_array[1] = 1 for i in range(2, n+1): fibo_array[i] = fibo_array[i-1]+fibo_array[i-2] print(fibo_array[-1]) ▼링크 https://www.acmicpc.net/problem/2748 2748번: 피보나치 수 2 문제 피보나치 수는 0과 1로 시작한다. 0번째 피보나치 수는 0이고, 1번째 피보나치 수는 1이다. 그 다음 2번째 부터는 바로 앞 두 피보나치 수의 합이 된다. 이를 식으로 써보면 Fn = Fn-1 + Fn-2 (n>=2)가 된다. n=17일때 까지 피보나치 수를 써보면 다음과 같다. 0, 1, 1, 2, 3..
![[백준 알고리즘] 2751번 수 정렬하기 2 (Python)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2F9KPfk%2FbtqDQbhY0hk%2F5QZz3Knd9cKHdEron4XIJK%2Fimg.png)
import sys n = int(sys.stdin.readline()) num_list = [] for _ in range(n): num_list.append(int(sys.stdin.readline())) num_list.sort() print("\n".join(list(map(str, num_list)))) 파이썬 sort함수는 시간복잡도 O(nlogn)이다. ▼ 링크 https://www.acmicpc.net/problem/2751 2751번: 수 정렬하기 2 첫째 줄에 수의 개수 N(1 ≤ N ≤ 1,000,000)이 주어진다. 둘째 줄부터 N개의 줄에는 숫자가 주어진다. 이 수는 절댓값이 1,000,000보다 작거나 같은 정수이다. 수는 중복되지 않는다. www.acmicpc.net
![[백준 알고리즘] 2108번 통계학 (Python)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FbAPQ6j%2FbtqDOktCX4x%2FO7fcUFUQs2F8CE5KbvO781%2Fimg.png)
import sys from collections import Counter n = int(sys.stdin.readline()) num_list = [] for _ in range(n): num_list.append(int(sys.stdin.readline())) num_list.sort() print(round(sum(num_list) / n)) # 산술평균 print(num_list[len(num_list) // 2]) # 중앙값 if len(num_list)>1: c = Counter(num_list).most_common(2) # 빈도수 print(c[1][0] if c[0][1] == c[1][1] else c[0][0]) else: print(num_list[0]) print(num_list..
![[백준 알고리즘] 10814번 나이순 정렬 (Python)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FZIV34%2FbtqDNopl5Ow%2FC69F7gpkxK0D3AbJq5HVEk%2Fimg.png)
import sys n = int(input()) u_list = [] for _ in range(n): line = sys.stdin.readline().split() u_list.append((int(line[0]), line[1])) u_list.sort(key=lambda x: x[0]) for mem in u_list: print(mem[0], mem[1]) ▼링크 https://www.acmicpc.net/problem/10814 10814번: 나이순 정렬 온라인 저지에 가입한 사람들의 나이와 이름이 가입한 순서대로 주어진다. 이때, 회원들을 나이가 증가하는 순으로, 나이가 같으면 먼저 가입한 사람이 앞에 오는 순서로 정렬하는 프로그램을 작성하시오. www.acmicpc.net