From 99ec61b418b6be26d37e2c81b67e841b8ea83ae4 Mon Sep 17 00:00:00 2001 From: Junseo Kim Date: Tue, 26 Mar 2024 10:05:53 +0900 Subject: [PATCH 1/3] =?UTF-8?q?2024-03-26=20=ED=9B=84=EC=9C=84=ED=91=9C?= =?UTF-8?q?=EA=B8=B0=EC=8B=9D2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oesnuj/README.md | 2 +- "oesnuj/\354\212\244\355\203\235/1935.cpp" | 43 ++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 "oesnuj/\354\212\244\355\203\235/1935.cpp" diff --git a/oesnuj/README.md b/oesnuj/README.md index 8134ba4..9132b27 100644 --- a/oesnuj/README.md +++ b/oesnuj/README.md @@ -2,5 +2,5 @@ | 차시 | 날짜 | 문제유형 | 링크 | 풀이 | |:----:|:---------:|:----:|:-----:|:----:| -| 1차시 | 2023.10.27 | BFS | - | - | +| 1차시 | 2024.03.26 | 스택 | https://www.acmicpc.net/problem/1935 | https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/4 | --- diff --git "a/oesnuj/\354\212\244\355\203\235/1935.cpp" "b/oesnuj/\354\212\244\355\203\235/1935.cpp" new file mode 100644 index 0000000..f5556bb --- /dev/null +++ "b/oesnuj/\354\212\244\355\203\235/1935.cpp" @@ -0,0 +1,43 @@ +#include +#include +#include +#include +using namespace std; + +int main() +{ + ios_base::sync_with_stdio(false); cin.tie(NULL); + stack s; + + int n; + cin >> n; + string postfix; + cin >> postfix; + double arr[26] = {0}; + for (int i = 0; i < n; i++) //알파벳에 해당하는 값 저장해놓기 + cin >> arr[i]; + + for (int i = 0; i < postfix.length(); i++) + { + if (postfix[i] >= 'A' && postfix[i] <= 'Z') //피연산자라면 해당 값 push + s.push(arr[postfix[i] - 'A']); + + else //연산자를 만난다면 스택의 top 2개를 꺼내어 연산 수행후 해당 값 push + { + double op1 = s.top(); + s.pop(); + double op2 = s.top(); + s.pop(); + if (postfix[i] == '+') + s.push(op2 + op1); + else if (postfix[i] == '-') + s.push(op2 - op1); + else if (postfix[i] == '*') + s.push(op2 * op1); + else if (postfix[i] == '/') + s.push(op2 / op1); + } + } + cout << fixed << setprecision(2) << s.top(); //소수점 둘째짜리 까지 출력 + return 0; +} \ No newline at end of file From 03c9d138c0d9e32f408b1011c2f7bf94e11f4f8d Mon Sep 17 00:00:00 2001 From: Junseo Kim Date: Tue, 26 Mar 2024 10:16:53 +0900 Subject: [PATCH 2/3] Update README.md --- oesnuj/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oesnuj/README.md b/oesnuj/README.md index 9132b27..1d81fdf 100644 --- a/oesnuj/README.md +++ b/oesnuj/README.md @@ -2,5 +2,5 @@ | 차시 | 날짜 | 문제유형 | 링크 | 풀이 | |:----:|:---------:|:----:|:-----:|:----:| -| 1차시 | 2024.03.26 | 스택 | https://www.acmicpc.net/problem/1935 | https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/4 | +| 1차시 | 2024.03.26 | 스택 | [후위표기식2]https://www.acmicpc.net/problem/1935 | [#4]https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/4 | --- From f4d6e3fe14585a2e8d6403112d7307283b554cb6 Mon Sep 17 00:00:00 2001 From: Junseo Kim Date: Tue, 26 Mar 2024 14:42:39 +0900 Subject: [PATCH 3/3] Update 1935.cpp --- "oesnuj/\354\212\244\355\203\235/1935.cpp" | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git "a/oesnuj/\354\212\244\355\203\235/1935.cpp" "b/oesnuj/\354\212\244\355\203\235/1935.cpp" index f5556bb..bb5c447 100644 --- "a/oesnuj/\354\212\244\355\203\235/1935.cpp" +++ "b/oesnuj/\354\212\244\355\203\235/1935.cpp" @@ -13,14 +13,14 @@ int main() cin >> n; string postfix; cin >> postfix; - double arr[26] = {0}; - for (int i = 0; i < n; i++) //알파벳에 해당하는 값 저장해놓기 - cin >> arr[i]; + double alphabet[26] = {0}; + for (int i = 0; i < n; i++) //피연산자(알파벳)에 대응되는 값 저장해놓기 + cin >> alphabet[i]; for (int i = 0; i < postfix.length(); i++) { if (postfix[i] >= 'A' && postfix[i] <= 'Z') //피연산자라면 해당 값 push - s.push(arr[postfix[i] - 'A']); + s.push(alphabet[postfix[i] - 'A']); else //연산자를 만난다면 스택의 top 2개를 꺼내어 연산 수행후 해당 값 push {