hdu 1237

来源:互联网 发布:灌篮高手java 编辑:程序博客网 时间:2024/06/04 20:11
#include <iostream>#include <cstdio>#include <cstring>using namespace std;int main(){char arr[500];while(1) {gets(arr);int len = strlen(arr);if(len == 1 && arr[0] == '0') break;double st1[300]; int top1 = 0;char st2[300]; int top2 = 0;  //cao zuo shufor(int i = 0; i < len; i++) {if(arr[i] == '+' || arr[i] == '-') {st2[top2++] = arr[i];}else if(arr[i] == '*' || arr[i] == '/') {bool flag = 0; if(arr[i] == '*') flag = 1;i += 2;double a = st1[top1-1], b = 0;while(arr[i] != ' ' && i < len) {b = b * 10 + (arr[i++]-'0');}if(flag) {st1[top1-1] = a * b; }else {st1[top1-1] = a / b; }}else if(arr[i] != ' ') {int res = 0;while(arr[i] != ' ' && i < len) {res = res * 10 + arr[i++]-'0';}if(st2[top2-1] == '-') {res = -res; st2[top2-1] = '+'; }st1[top1++] = res; }}while(top2 > 0) {double a;a = st1[top1-1]; top1--;st1[top1-1] = st1[top1-1] + a;top2--;}printf("%.2lf\n", st1[top1-1]);}return 0;}

0 0
原创粉丝点击