공부/C, C++
-
[BOJ] 10828 스택 / C++공부/C, C++ 2023. 1. 3. 19:46
https://www.acmicpc.net/problem/10828 10828번: 스택 첫째 줄에 주어지는 명령의 수 N (1 ≤ N ≤ 10,000)이 주어진다. 둘째 줄부터 N개의 줄에는 명령이 하나씩 주어진다. 주어지는 정수는 1보다 크거나 같고, 100,000보다 작거나 같다. 문제에 나와있지 www.acmicpc.net #include #include #define MAX_CAPACITY10000 #define EMPTY0 #define FULLMAX_CAPACITY using namespace std; int N; // 명령의 수 (1 N; for(int i=0; i> cmd; if (cmd == "push") { cin >> num; push(num); } else if (cmd == "po..
-
[C++] STL - map, set공부/C, C++ 2022. 5. 12. 17:33
STL container - 시퀀스 컨테이너 / 연관 컨테이너 시퀀스 컨테이너: vector, list, deque 등 순서대로 데이터를 보관할때 사용 연관 컨테이너: map, set 등 형태로 데이터를 보관할때 사용. 찾고자하는 데이터를 빠르게 찾을 때 사용. map, set key의 중복을 허용하지 않음 중복되는 key를 사용하는 경우에는 컨테이너 앞에 'multi'를 붙임. ex) multi_map, multi_set key 기준으로 데이터를 정렬하여 저장함 map Red-Black tree 자료구조를 가짐 형태로 데이터를 저장 key를 기준으로 오름차순 정렬함 map 선언 예시) #include map map1; set map과 비슷하지만 map과 달리 key만 저장함 key를 기준으로 오름차순 ..
-
[C++] sort( )를 이용한 구조체 정렬공부/C, C++ 2022. 1. 12. 01:05
#include #include #include using namespace std; int N; struct st { int start, end; }; struct st meeting[100000 + 10]; bool cmp(const struct st &m1, const struct st &m2) { if (m1.start < m2.start) { return true; } else if (m1.start == m2.start) { return m1.end < m2.end; } else { return false; } } int main(void) { scanf("%d", &N); for (int i = 0; i < N; i++) { scanf("%d %d", &meeting[i].start, &me..