Algorithm(218)
-
[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 -
[BOJ] 1158번 : 요세푸스
1. problem : https://www.acmicpc.net/problem/1158 2. solution 1 :from collections import dequeN,K = map(int,input().split())deq = deque([i+1 for i in range(N)])count = 0 result = []while deq: count += 1 if count == K: result.append(deq.popleft()) count = 0 else: deq.append(deq.popleft())print('')deque을 이용한 풀이 3. solution 2 :#include using namespace std;int main(v..
2024.08.06 -
[BOJ] 5397번 : 키로거
1. problem : https://www.acmicpc.net/problem/5397 2. solution 1 : #include using namespace std;int main(void) { ios::sync_with_stdio(0); cin.tie(0); int testCase; cin >> testCase; while (testCase--) { list L = {}; auto cursor = L.begin(); string init; cin >> init; for (auto c : init) { if (c == '') { if (cursor != L.end..
2024.08.05 -
[BOJ] 1406: 에디터
1. problem :https://www.acmicpc.net/problem/1406 2. solution 1 :import sysinput = sys.stdin.readclass Node: def __init__(self, val): self.val = val self.next = None self.prev = Noneclass DoublyLinkedList: def __init__(self): dummy_node = Node(0) self.head = dummy_node self.tail = dummy_node def erase(self, current_node): if current_no..
2024.08.05