#include<bits/stdc++.h> using namespace std; char c[1001][10]; int main(){ stack s; int k=0; while(cin>>c[k]) k++; for(int i=0;i<=k-2;i++){ switch (c[i][0]) { double a,b; case '+': a=s.top();s.pop(); b=s.top();s.pop(); s.push(b+a); break; case '-': a=s.top();s.pop(); b=s.top();s.pop(); s.push(b-a); break; case '': a=s.top();s.pop(); b=s.top();s.pop(); s.push(ba); break; case '/': a=s.top();s.pop(); b=s.top();s.pop(); s.push(b/a); break; default: s.push(atof(c[i])); } } cout<<fixed<<setprecision(0)<<s.top(); return 0; }

2 条评论

  • @ 2026-5-17 16:27:42

    #include<bits/stdc++.h> using namespace std; char c[1001][10]; int main(){ stack s; int k=0; while(cin>>c[k]) k++; for(int i=0;i<=k-2;i++){ switch (c[i][0]) { double a,b; case '+': a=s.top();s.pop(); b=s.top();s.pop(); s.push(b+a); break; case '-': a=s.top();s.pop(); b=s.top();s.pop(); s.push(b-a); break; case '': a=s.top();s.pop(); b=s.top();s.pop(); s.push(ba); break; case '/': a=s.top();s.pop(); b=s.top();s.pop(); s.push(b/a); break; default: s.push(atof(c[i])); } } cout<<fixed<<setprecision(0)<<s.top(); return 0; }

    • @ 2026-5-17 16:26:51

      666

      • 1

      信息

      ID
      1973
      时间
      ms
      内存
      MiB
      难度
      2
      标签
      递交数
      169
      已通过
      25
      上传者