[B17219][비밀번호 찾기][C++] #include #include #include using namespace std; map M; int n, m; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> m; for (int i = 0; i > site >> pw; M[site] = pw; } for (int i = 0; i > s; cout BAEKJOON/C++ 2021.06.21
[B7662][이중 우선 순위 큐][C++] #include #include #include #include #include using namespace std; const int MAX = 1000001; int n; bool visit[MAX]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int test; cin >> test; for (int t = 0; t > n; priority_queue minpq; priority_queue maxpq; for (int i = 0; i > c >> num; if (c == 'I') { maxpq.push({ num, i }); m.. BAEKJOON/C++ 2021.06.17
[B1927][최소 힙][C++] #include #include using namespace std; int n, x; priority_queue pq; // 우선순위 큐 int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n; while (n--) { cin >> x; if (x == 0) { // pq.size() 로도 가능 if (pq.empty()) cout BAEKJOON/C++ 2021.06.15
[B11279][최대 힙][C++] #include #include using namespace std; int n, x; priority_queue pq; // 우선순위 큐 int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n; while (n--) { cin >> x; if (x == 0) { if (pq.empty()) cout BAEKJOON/C++ 2021.06.15
[B1764][듣보잡][C++] #include #include #include using namespace std; int n, m; vector v; bool binary_search(int low, int high, string name) { if (low > high) return false; else { int mid = (low + high) / 2; if (name == v[mid]) return true; else if (v[mid] > name) return binary_search(low, mid - 1, name); else return binary_search(mid + 1, high, name); } } int main(void) { cin >> n >> m; for (int i = 0; i < n; i++) {.. BAEKJOON/C++ 2021.06.07
[B1620][나는야 포켓몬 마스터 이다솜][C++] #include #include #include #include #include using namespace std; int n, m; int result; char str[21]; map mp1; // 문자열 기준 정렬 string mp2[100001]; // 번호 기준 정렬 int main(void) { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // 포켓몬 입력 cin >> n >> m; for (int i = 0; i > tmp; mp1.insert(pair(tmp, i)); mp2[i] = tmp; } // 문자열 또는 번호 검색 for (int i = 0; i < m; .. BAEKJOON/C++ 2021.06.07
[B11866][요세푸스 문제 0][python] n, k = map(int, input().split()) p = list(range(1, n+1)) ans = [] i = k-1 while len(ans) < n-1: ans.append(p.pop(i)) i = (i + k-1) % len(p) ans.append(p[0]) print('') BAEKJOON/Python 2021.03.18
[B2164][카드][python] import sys from collections import deque n = int(sys.stdin.readline()) q = deque() for i in range(n): q.append(i + 1) while len(q) > 1: q.popleft() q.append(q.popleft()) print(q.pop()) BAEKJOON/Python 2021.03.18
[B10886][덱][python] import sys from collections import deque n = int(sys.stdin.readline()) dq = deque() for i in range(n): cmd = list(sys.stdin.readline().split()) if cmd[0] == 'push_front': dq.appendleft(cmd[1]) elif cmd[0] == 'push_back': dq.append(cmd[1]) elif cmd[0] == "pop_front": if len(dq) == 0: print('-1') else: print(dq.popleft()) elif cmd[0] == "pop_back": if len(dq) == 0: print('-1') else: print(dq.pop().. BAEKJOON/Python 2021.03.18
[B10828][스택][python] import sys n = int(sys.stdin.readline()) stack = list() for i in range(n): cmd = sys.stdin.readline().split() if cmd[0] == 'push': stack.append(cmd[1]) elif cmd[0] == 'pop': if not stack: print('-1') else: print(stack.pop()) elif cmd[0] == 'size': print(len(stack)) elif cmd[0] == 'empty': if not stack: print('1') else: print('0') elif cmd[0] == 'top': if not stack: print('-1') else: print(stack[.. BAEKJOON/Python 2021.03.17
[B9012][괄호][python] n = int(input()) for i in range(n): sentence = list(input()) cnt = 0 for s in sentence: if s == '(': cnt += 1 elif s == ')': cnt -= 1 if cnt 0: print('NO') elif cnt == 0: print('YES') BAEKJOON/Python 2021.03.16
[B10816][숫자 카드 2][python] n = int(input()) card = list(map(int, input().split())) m = int(input()) have = list(map(int, input().split())) dic = dict() for c in card: if c not in dic: dic[c] = 1 else: dic[c] += 1 for h in have: if h in dic: print(str(dic[h]), end = " ") else: print("0", end = " ") BAEKJOON/Python 2021.03.15