#include <stdio.h>#include <stack>#include <math.h>#include <string.h>#include <ctype.h>int main(){ int n; scanf("%d",&n); while(n--){ char s[1005]; scanf("%s",s+1); int len=strlen(s+1); std::stack<char>osta; std::stack<double>dsta; osta.push('(');s[len]=')'; for(int i=1;i<=len;i++){ if(s[i]=='(') osta.push('('); else if(isdigit(s[i])){ double d=0.0; int dot=0; while(isdigit(s[i])||s[i]=='.'){ if(isdigit(s[i])) d = d*10+(s[i]-'0'); else dot=i; i++; } i--; if(dot!=0) dsta.push(d/pow(10,i-dot)); else dsta.push(d); } else if(s[i]=='+'||s[i]=='-'){ while(osta.top()!='('){//必须用while不能用if double a=dsta.top(); dsta.pop(); double b=dsta.top(); dsta.pop(); switch(osta.top()){ case '+':dsta.push(b+a);break; case '-':dsta.push(b-a);break; case '*':dsta.push(b*a);break; case '/':dsta.push(b/a*1.0);break; } osta.pop(); } osta.push(s[i]); } else if(s[i]=='*'||s[i]=='/'){ if(osta.top()!='(' && osta.top()!='+' && osta.top()!='-'){ double a=dsta.top(); dsta.pop(); double b=dsta.top(); dsta.pop(); switch(osta.top()){ case '*':dsta.push(b*a);break; case '/':dsta.push(b/a*1.0);break; } osta.pop(); } osta.push(s[i]); } else if(s[i]==')'){ while(osta.top()!='('){ double a=dsta.top(); dsta.pop(); double b=dsta.top(); dsta.pop(); switch(osta.top()){ case '+':dsta.push(b+a);break; case '-':dsta.push(b-a);break; case '*':dsta.push(b*a);break; case '/':dsta.push(b/a*1.0);break; } osta.pop(); } osta.pop(); } } printf("%.2lf\n",dsta.top()); dsta.pop();//一定记得要回收 } return 0;}