[C++] 2*n 타일링 2 - 11727 #include using namespace std; int a[1001] = {0}; int tiling(int n) { if (n == 1) return 1; if (n == 2) return 3; if (a[n] != 0) return a[n]; return a[n] = (tiling(n - 1) + (tiling(n - 2)*2)) % 10007; } int main() { int N = 0; cin >> N; cout 알고리즘 문제/백준 2022.11.26
[C++] 2*n 타일링 - 11726 #include using namespace std; int a[1001] = {0}; int tiling(int n) { if (n == 1) return 1; if (n == 2) return 2; if (a[n] != 0) return a[n]; return a[n] = (tiling(n - 1) + tiling(n - 2)) % 10007; } int main() { int N = 0; cin >> N; cout 알고리즘 문제/백준 2022.11.26
[C++] 수 정렬하기 2(병합정렬) - 2751 #include #include using namespace std; vector merge(vector v1, vector v2) { vector m; auto iter1 = v1.begin(); auto iter2 = v2.begin(); while (iter1 != v1.end() && iter2 != v2.end()) { if (*iter1 > *iter2) { m.push_back(*iter2); ++iter2; } else { m.push_back(*iter1); ++iter1; } } if (iter1 != v1.end()) { for (; iter1 != v1.end(); ++iter1) m.push_back(*iter1); } else { for (; iter2 != v2.end(); +.. 알고리즘 문제/백준 2022.11.22
[C++] 쇠막대기 - 10799 #include #include using namespace std; int main() { string str; int bar = 0; int num = 0; getline(cin, str); for (int i = 0; i < str.size(); i++) { if (str[i] == '(') bar++; else if (str[i] == ')' && str[i - 1] == '(' ) { bar--; num += bar; } else if (str[i] == ')') { bar--; num++; } } cout 알고리즘 문제/백준 2022.11.19
[C++] 단어 뒤집기2(stack) - 17413 #include #include #include using namespace std; string RvsWord(string& str) { int size = static_cast(str.length()) - 1; string c = ""; int be = 0; stack st; for (int i = 0; i 0) { c += str[i]; if (str[i] == '>') be = be > 0 ? be - 1: 0; if (be == 0) { if (str[i + 1] == ' 알고리즘 문제/백준 2022.11.18
[C++] 덱(deque) - 10866 #include #include using namespace std; class Deque { public: void push_front(int n) { _arr[_front--] = n; _front = (10000 + _front) % 10000; _size++; } void push_back(int n) { _arr[_back++] = n; _back = (10000 + _back) % 10000; _size++; } void pop_front() { if (_size == 0) return; _front = (10000 + _front + 1) % 10000; _size--; } void pop_back() { if (_size == 0) return; _back = (10000 + _back -.. 알고리즘 문제/백준 2022.11.18
[C++] 스택 - 10828 #include #include using namespace std; class Stack { public: void push(int x) { t[++_top] = x; } void pop() { if (_top >= 0) _top--; return; } int size() { return _top + 1; } bool empty() { if (_top == -1) return true; return false; } int top() { if (_top == -1) return -1; return t[_top]; } public: int* t = new int[10000]; int _top = -1; }; int main() { Stack s; int N; cin >> N; string str; for .. 알고리즘 문제/백준 2022.11.17
[C++] 요세푸스(Queue) - 1158 #include #include using namespace std; int main() { queue q; int N, K; cin >> N; cin >> K; for (int i = 1; i < N + 1; i++) q.push(i); cout 알고리즘 문제/백준 2022.11.16
[C++] 에디터(list) - 1406 #include #include #include using namespace std; int main() { string str = ""; list d; int N = 0; char c; cin >> str; cin >> N; for (int i = 0; i > c; if (c == 'L') { if (it != d.begin()) it--; } else if (c == 'D') { if (it != d.end()) it++; } else if (c == 'B') { if (it != d.begin()) it = d.erase(--it); } els.. 알고리즘 문제/백준 2022.11.16
[C++] 큐 - 10845 #include #include using namespace std; class Queue { public: void push(int n) { _back = n; arr[_top++] = n; } void pop() { if (_top str; if (str == "push") { cin >> pN; q.push(pN); } else if (str == "pop") { if (q.empty()) cout 알고리즘 문제/백준 2022.11.16