diff options
author | Nguyễn Gia Phong <vn.mcsinyx@gmail.com> | 2020-01-14 18:29:11 +0700 |
---|---|---|
committer | Nguyễn Gia Phong <vn.mcsinyx@gmail.com> | 2020-01-14 18:29:11 +0700 |
commit | a3dd2581ed4847670f81157091016c14ca18803d (patch) | |
tree | 3362ab15de119f1e75799f58715b7683e6bfd6ca /usth/MATH2.3/3/dc.cc | |
parent | 65b8ebda4c47fa27ac28899fb2b29097f445b6df (diff) | |
download | cp-a3dd2581ed4847670f81157091016c14ca18803d.tar.gz |
[usth/MATH2.3] Mathemate Discretely
Diffstat (limited to 'usth/MATH2.3/3/dc.cc')
-rw-r--r-- | usth/MATH2.3/3/dc.cc | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/usth/MATH2.3/3/dc.cc b/usth/MATH2.3/3/dc.cc new file mode 100644 index 0000000..b69742a --- /dev/null +++ b/usth/MATH2.3/3/dc.cc @@ -0,0 +1,43 @@ +#include <cmath> +#include <iostream> +#include <sstream> +#include <string> +#include <vector> + +using namespace std; + +int +main () +{ + double num, x, y; + string op; + vector<double> v; + + while (cin.peek () != '\n') + { + getline (cin, op, ';'); + stringstream s {op}; + s >> num; + if (s) + { + v.push_back (num); + continue; + } + + y = v.back (); + v.pop_back (); + x = v.back (); + v.pop_back (); + if (op == "^") + v.push_back (pow (x, y)); + else if (op == "+") + v.push_back (x + y); + else if (op == "-") + v.push_back (x - y); + else if (op == "*") + v.push_back (x * y); + else if (op == "/") + v.push_back (x / y); + } + cout << v.back () << endl; +} |