-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from AlgoLeadMe/origin/1-oesnuj
1-oesnuj
- Loading branch information
Showing
2 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |