본문 바로가기

스택 큐 덱10

[백준/BOJ][C++] 24511번 queuestack #include #include #include #include #include using namespace std; int main() { // 쓰레드 환경이 아닐때 버퍼를 분리하여 처리속도를 빠르게 해줌 ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int N; cin >> N; vector A(N); // 큐인지 스택인지 구별하는 수열 for (int i = 0; i > A[i]; vector B(N); // 각 자료구조에 들어있는 원소들의 수열 for (int i = 0; i > B[i]; int M; cin >> M; deque C(M); // 삽입할 원소를 담은 수열 fo.. 2023. 8. 30.
[백준/BOJ][C++] 2346번 풍선 터뜨리기 #include #include #include using namespace std; int main() { // 쓰레드 환경이 아닐때 버퍼를 분리하여 처리속도를 빠르게 해줌 ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int N; cin >> N; deque ballonNum(N); // 풍선번호 vector paperNum(N); // 종이번호 // 풍선번호와 종이번호 입력 for (int i = 0; i > paperNum[i]; // 입력된 값 } int nextMove = 0; // 다음으로 이동하는 칸 수 // 풍선을 터뜨리는 순서대로 번.. 2023. 8. 28.
[백준/BOJ][C++] 28279번 덱 2 #include #include using namespace std; struct Deque { private: int* elements; int frontIndex; int backIndex; int MAX_SIZE; public: Deque(int n) { elements = new int[n]; frontIndex = 0; backIndex = 0; MAX_SIZE = n; } void push_front(int x) { // front는 0부터 뒤로가면서 원소를 삽입 elements[frontIndex] = x; frontIndex = ((frontIndex - 1) + MAX_SIZE) % MAX_SIZE; } void push_back(int x) { // back은 1부터 앞으로가면서 원소를.. 2023. 8. 26.
[백준/BOJ][C++] 11866번 요세푸스 문제0 #include #include using namespace std; int main() { // 쓰레드 환경이 아닐때 버퍼를 분리하여 처리속도를 빠르게 해줌 ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int N, K; cin >> N >> K; queue circle; // 순서대로 사람을 앉힘 for (int i = 1; i 2023. 8. 24.
[백준/BOJ][C++] 2164번 카드2 #include #include using namespace std; void Shuffle(queue& q) { q.pop(); // 맨 위의 카드를 버림 q.push(q.front()); // 그 다음 맨 위의 카드를 밑으로 옮김 q.pop(); // 옮긴 카드를 버림 } int main() { // 쓰레드 환경이 아닐때 버퍼를 분리하여 처리속도를 빠르게 해줌 ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int N; cin >> N; queue q; // 1부터 N까지 수를 큐에 담음 for (int i = 1; i 2023. 8. 24.
[백준/BOJ][C++] 18258번 큐 2 #include #include using namespace std; struct Queue { private: int* elements; int frontIndex; int backIndex; public: Queue(int n) { elements = new int[n]; frontIndex = 0; backIndex = -1; } ~Queue() {} void push(int x) { elements[++backIndex] = x; } int pop() { if (empty()) return -1; else { return elements[frontIndex++]; } } int size() { return backIndex - frontIndex + 1; } bool empty() { if (fr.. 2023. 8. 24.
[백준/BOJ][C++] 12789번 도키도키 간식드리미 #include #include #include using namespace std; int main() { // 쓰레드 환경이 아닐때 버퍼를 분리하여 처리속도를 빠르게 해줌 ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int N; cin >> N; queue curLine; // 현재 줄 stack otherLine; // 또 다른 줄 for (int i = 0; i > x; curLine.push(x); } int checkNum = 1; while (true) { if (!curLine.empty() && curLine.front() == checkNum) { // 현재 줄에 순서에 맞.. 2023. 8. 23.
[백준/BOJ][C++] 4949번 균형잡힌 세상 #include #include #include #include using namespace std; int main() { // 쓰레드 환경이 아닐때 버퍼를 분리하여 처리속도를 빠르게 해줌 ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); vector output; while(true) { string s; getline(cin, s); // 공백 포함 문자열 입력 if (s == ".") break; stack stk; bool isBalanced = true; // 균형유무 for (int j = 0; j < s.size(); j++) { char curWord = s[j]; if (curWord == '(' || curWord ==.. 2023. 8. 21.
[백준/BOJ][C++] 9012번 괄호 #include #include #include #include using namespace std; int main() { // 쓰레드 환경이 아닐때 버퍼를 분리하여 처리속도를 빠르게 해줌 ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int T; cin >> T; vector output; for (int i = 0; i > s; stack stk; bool isVPS = true; for (int j = 0; j < s.size(); j++) { char curWord = s[j]; if (curWord == '(') { // '('인 경우 스택에 넣어줌 stk.push(curWor.. 2023. 8. 21.
[백준/BOJ][C++] 10773번 제로 #include #include using namespace std; int main() { // 쓰레드 환경이 아닐때 버퍼를 분리하여 처리속도를 빠르게 해줌 ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int K; cin >> K; stack stk; int sum = 0; for (int i = 0; i > x; if (x == 0) { sum -= stk.top(); stk.pop(); } else { stk.push(x); sum += x; } } cout 2023. 8. 21.