Skip to content

Commit

Permalink
Merge pull request #4 from AlgoLeadMe/origin/1-oesnuj
Browse files Browse the repository at this point in the history
1-oesnuj
  • Loading branch information
oesnuj authored Mar 29, 2024
2 parents 709820a + f4d6e3f commit 6a1959d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion oesnuj/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

| μ°¨μ‹œ | λ‚ μ§œ | λ¬Έμ œμœ ν˜• | 링크 | 풀이 |
|:----:|:---------:|:----:|:-----:|:----:|
| 1μ°¨μ‹œ | 2023.10.27 | BFS | - | - |
| 1μ°¨μ‹œ | 2024.03.26 | μŠ€νƒ | [ν›„μœ„ν‘œκΈ°μ‹2]https://www.acmicpc.net/problem/1935 | [#4]https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/4 |
---
43 changes: 43 additions & 0 deletions oesnuj/μŠ€νƒ/1935.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <iostream>
#include <string>
#include <stack>
#include <iomanip>
using namespace std;

int main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL);
stack <double> s;

int n;
cin >> n;
string postfix;
cin >> postfix;
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(alphabet[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;
}

0 comments on commit 6a1959d

Please sign in to comment.