hdu 1237

#include 
#include 
#include 
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 shu

		for(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;
}

你可能感兴趣的:(Water,Problem)