标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 14590 Accepted Submission(s): 4957
1 + 2 4 + 2 * 5 - 7 / 11 0
3.00 13.36
#include <stdio.h> #include<stack> using namespace std; int main() { double m,n; char ch; while(~scanf("%lf",&m)) { if(getchar() == ‘\n‘ && m == 0 ) break ; stack <double> s; s.push(m) ; scanf("%c",&ch); //执行一次; while(~scanf("%lf",&m)) { if(ch == ‘*‘) { n=s.top() ; n*=m ; s.pop() ; s.push(n) ; } if( ch == ‘/‘) { n=s.top() ; n/=m ; s.pop() ; s.push(n) ; } if(ch == ‘+‘) s.push(m) ; if(ch == ‘-‘) s.push(-m) ; if(getchar() == ‘\n‘) break; //ch=getchar(); //gethchar() ; 相当于输入一个人字符; scanf("%c",&ch); } double total =0; while(!s.empty()) { total+=s.top() ; s.pop() ; } printf("%.2lf\n",total); } return 0; }
标签:
原文地址:http://www.cnblogs.com/fengshun/p/4612278.html