fork download
  1. /* Author haleyk10198 */
  2. /* §@ªÌ: haleyk10198 */
  3. #include <bits/stdc++.h>
  4.  
  5. #define MOD 1000000007
  6. #define LINF (1LL<<60)
  7. #define INF 2147483647
  8. #define PI 3.1415926535897932384626433
  9. #define ll long long
  10. #define pii pair<int,int>
  11. #define mp(x,y) make_pair((x),(y))
  12.  
  13. using namespace std;
  14.  
  15. string itos(int x){
  16. stringstream ss;
  17. ss<<x;
  18. return ss.str();
  19. }
  20.  
  21. struct Node{
  22. int type;
  23. double value;
  24. string operation;
  25. Node(double x){
  26. type = 0;
  27. operation = "NULL";
  28. value = x;
  29. }
  30. Node(string str){
  31. type = 1;
  32. value = 0;
  33. operation = str;
  34. }
  35. };
  36.  
  37. vector<Node> v;
  38. const string alphanumeric="QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm1234567890.";
  39.  
  40. //¤j«e´£: inputªº®æ¦¡¤£©¿±y§Ú¡C ³oùاڴN¤£¬G·N¦Ò¼{input®æ¦¡¿ù»~ªº±¡ªp¤F¡C
  41.  
  42. int main(){
  43. //freopen("input.txt","r",stdin);
  44. //freopen("output.txt","w",stdout);
  45. ios_base::sync_with_stdio(false);
  46. string tmp;
  47. getline(cin,tmp,'\n');
  48. {
  49. int pos = 0;
  50. while(pos != tmp.length()){
  51. pos = tmp.find_first_of(alphanumeric, pos);
  52. if(pos == string::npos)
  53. break;
  54. int nxt = tmp.find(' ', pos);
  55. if(nxt == string::npos)
  56. nxt = tmp.length();
  57. if((tmp[pos] >= '0' && tmp[pos] <= '9') || tmp[pos] == '.')
  58. v.push_back(Node(stod(tmp.substr(pos, nxt-pos))));
  59. else
  60. v.push_back(Node(tmp.substr(pos, nxt-pos)));
  61. pos = nxt;
  62. }
  63. }
  64. {
  65. vector<Node> st;
  66. for(auto x:v){
  67. st.push_back(x);
  68. while(st.size() > 2 && !(st[st.size() - 1].type || st[st.size() - 2].type)){
  69. double a = st.back().value;
  70. st.pop_back();
  71. double b = st.back().value;
  72. st.pop_back();
  73. string operation = st.back().operation;
  74. st.pop_back();
  75. double res;
  76. if(operation == "ADD")
  77. res = a + b;
  78. else if(operation == "SUB")
  79. res = a - b;
  80. else if(operation == "MUL")
  81. res = a * b;
  82. else if(operation == "MAX")
  83. res = max(a, b);
  84. else if(operation == "MIN")
  85. res = min(a, b);
  86. st.push_back(res);
  87. }
  88. }
  89. cout<<st.back().value<<endl;
  90. }
  91. return 0;
  92. }
  93.  
Success #stdin #stdout 0s 3472KB
stdin
ADD .14 MAX ADD 2 3 MUL 2 3 
stdout
6.14