标签:
Description
Input
Output
Sample Input
Sample Output
1 #include <iostream>
2 #include <stack>
3 #include <stdio.h>
4 using namespace std;
5
6 int main()
7 {
8 double num1;
9 char ch;
10 while (cin>>num1)
11 {
12 stack<double> data;
13 ch=getchar();
14 if (num1==0&&ch==‘\n‘)
15 {
16 break;
17 }//结束
18
19 double num2;
20 while (cin>>ch)
21 {
22 if (ch==‘+‘||ch==‘-‘)
23 {
24 cin>>num2;
25 if (ch==‘-‘) num2=-num2;
26 data.push(num1);
27 num1=num2;
28 ch=getchar();
29 if (ch==‘\n‘)
30 {
31 data.push(num1);
32 break;
33 }
34 }
35 if (ch==‘*‘||ch==‘/‘)
36 {
37 cin>>num2;
38 if(ch==‘*‘)
39 {
40 num1*=num2;
41 ch=getchar();
42 if (ch==‘\n‘)
43 {
44 data.push(num1);
45 break;
46 }
47 }
48 if (ch==‘/‘)
49 {
50 num1/=num2;
51 ch=getchar();
52 if (ch==‘\n‘)
53 {
54 data.push(num1);
55 break;
56 }
57 }
58 }
59 }
60 double ans=0;
61 while (!data.empty())
62 {
63 ans+=data.top();
64 data.pop();
65 }
66 printf("%.2lf\n",ans);
67 }
68 return 0;
69 }
标签:
原文地址:http://www.cnblogs.com/haoabcd2010/p/5676718.html