Skip to content

Instantly share code, notes, and snippets.

@kira924age
Created December 2, 2017 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kira924age/295c332151689c7f1391ed6416ab7e15 to your computer and use it in GitHub Desktop.
Save kira924age/295c332151689c7f1391ed6416ab7e15 to your computer and use it in GitHub Desktop.
#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