전체 글(334)
-
[BOJ] 10866번 : 덱
1. problem :https://www.acmicpc.net/problem/10866 2. solution 1 :#include using namespace std;const int MX = 1000005;int dat[2 * MX + 1];int head = MX, tail = MX; void push_front(int x) { dat[--head] = x;}void push_back(int x) { dat[tail++] = x;}int pop_front() { if (head == tail) return -1; return dat[head++];}int pop_back() { if (head == tail) return -1; return dat[--tail];}int front() { if (h..
2024.08.07 -
[BOJ] 2164번 : 카드2
1. problem : https://www.acmicpc.net/problem/2164 2. solution 1 :#include using namespace std;int main(void) { ios::sync_with_stdio(0); cin.tie(0); queue Q; int N; cin >> N; for (int i = 1; i 1) { Q.pop(); // 첫 번째 요소를 제거 int temp = Q.front(); // 두 번째 요소를 temp에 저장 Q.pop(); // 두 번째 요소 제거 Q.push(temp); // 두 번째 요소를 큐의 뒤로 이동 } cout
2024.08.07 -
[BOJ] 10845 : 큐
1. problem : https://www.acmicpc.net/problem/10845 2. solution 1 :#include using namespace std;const int MX = 100001;int dat[MX];int fir = 0, fin = 0;void push(int x) { dat[fin++] = x;}int pop() { if (fir == fin) return -1; return dat[fir++];}int empty() { return (fir == fin) ? 1 : 0;}int size() { return fin - fir;}int front() { if (fir == fin) return -1; return dat[fir];}in..
2024.08.07 -
[BOJ] 2493: 탑
1. problem :https://www.acmicpc.net/problem/2493 2. solution 1 :#include using namespace std; int main(void) { ios::sync_with_stdio(0); cin.tie(0); int N; cin >> N; stack s; vector v(N); vector ans(N); int i = 0; for (int i = 0; i > v[i]; } for (int i = 0; i 3. solution 2 :#include using namespace std;#define X first#define Y secondint N;stack> tower;int main() { ios_base::sync_with_stdio(0); ..
2024.08.07 -
[BOJ]1874번 : 스택 수열
1. problem : https://www.acmicpc.net/problem/1874 2. solution 1 :#include using namespace std; int main(void) { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector ans; vector v; stack s; for (int i = 1; i > x; v.push_back(x); } int number = 1; for (int i = 0; i 여기서 const auto& op : ans의 뜻은 ans의 값의 원본을 가져온다는 뜻이다. 즉, 변경가능한 상태가 된다. 하지만 const를 붙여, 변경을 불가능하게 만들었다.
2024.08.06 -
[BOJ]10773번 : 제로
1. problem :https://www.acmicpc.net/problem/10773 2. solution 1 :#include using namespace std; int main(void) { ios::sync_with_stdio(0); cin.tie(0); stack s; int K; cin >> K; while (K--) { int op; cin >> op; if (op != 0) s.push(op); else s.pop(); } int ans = 0; while (!s.empty()) { ans += s.top(); s.pop(); } cout
2024.08.06