Created
December 2, 2017 14:29
-
-
Save kira924age/295c332151689c7f1391ed6416ab7e15 to your computer and use it in GitHub Desktop.
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
#include <iostream> | |
#include <string> | |
#include <sstream> | |
#include <stack> | |
#include <cstdlib> | |
#include <cctype> | |
#include <cstdio> | |
using namespace std; | |
int main() { | |
string s; | |
stack<double> St; | |
double a, b; | |
while (getline(cin, s)) { | |
stringstream ss(s); | |
while (ss >> s) { | |
if (s == "+") { | |
b = St.top(); St.pop(); | |
a = St.top(); St.pop(); | |
St.push(a+b); | |
} | |
else if (s == "-") { | |
b = St.top(); St.pop(); | |
a = St.top(); St.pop(); | |
St.push(a-b); | |
} | |
else if (s == "*") { | |
b = St.top(); St.pop(); | |
a = St.top(); St.pop(); | |
St.push(a*b); | |
} | |
else if (s == "/") { | |
b = St.top(); St.pop(); | |
a = St.top(); St.pop(); | |
St.push(a/b); | |
} | |
else { | |
St.push(atoi(s.c_str())); | |
} | |
} | |
printf("%.6f\n", St.top()); | |
St.pop(); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment