Skip to content

Commit

Permalink
11차시 업로드
Browse files Browse the repository at this point in the history
  • Loading branch information
YIM2UL2ET committed Mar 18, 2024
1 parent beae178 commit 3131c76
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions YIM2UL2ET/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
| 08차시 | 2024.03.04 | 재귀 | [BOJ 10994](https://www.acmicpc.net/problem/10994) | [BOJ 10994 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/27) |
| 09차시 | 2024.03.07 | 임의 정밀도 / 큰 수 연산 && 재귀 | [BOJ 1914](https://www.acmicpc.net/problem/1914) | [BOJ 1914 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/29) |
| 10차시 | 2024.03.10 | 스택 | [BOJ 1406](https://www.acmicpc.net/problem/1406) | [BOJ 1406 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/31) |
| 11차시 | 2024.03.18 | 스택 | [BOJ 1918](https://www.acmicpc.net/problem/1918) | [BOJ 1918 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/36) |
---
43 changes: 43 additions & 0 deletions YIM2UL2ET/스택/11차시 - BOJ 1918.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <iostream>
#include <stack>

int main(void)
{
char ch;
std::stack <char> stk;
std::string res;

ch = getchar();
while (ch != '\n') {
if (ch == '+' || ch == '-') {
while(!stk.empty() && stk.top() != '(') {
res.push_back(stk.top());
stk.pop();
}
stk.push(ch);
}
else if (ch == '*' || ch == '/') {
if (!stk.empty() && (stk.top() == '*' || stk.top() == '/')) {
res.push_back(stk.top());
stk.pop();
}
stk.push(ch);
}
else if (ch == ')') {
while (!stk.empty() && stk.top() != '(') {
res.push_back(stk.top());
stk.pop();
}
if (!stk.empty()) stk.pop();
}
else if (ch == '(') stk.push(ch);
else res.push_back(ch);
ch = getchar();
}
while (!stk.empty()) {
res.push_back(stk.top());
stk.pop();
}
std::cout << res;
return 0;
}

0 comments on commit 3131c76

Please sign in to comment.