#includestdio.h #includestdlib.h #includestack #includeiostream using namespace std; char a[1222]; double aa[1222]; int main() { int Is(int x,int y); int n; int i,j,k; int c; double x,y,z; int t; scanf("%d",n); while(n--) { stackintp2; stac
#include<stdio.h>
#include<stdlib.h>
#include<stack>
#include<iostream>
using namespace std;
char a[1222];
double aa[1222];
int main()
{
int Is(int x,int y);
int n;
int i,j,k;
int c;
double x,y,z;
int t;
scanf("%d",&n);
while(n--)
{
stack<int>p2;
stack<double>p1;
p2.push(-61);
scanf("%s",a);
j=0;
for(i=0;a[i]!=0;i++)
{
if(a[i]>='0'&&a[i]<='9')
{
z=atof(a+i);
aa[j++]=z;
while(a[i]>='0'&&a[i]<='9'||a[i]=='.')
i++;
i--;
}
else
{
if(a[i]=='+')
aa[j++]=-43;
if(a[i]=='-')
aa[j++]=-45;
if(a[i]=='*')
aa[j++]=-42;
if(a[i]=='/')
aa[j++]=-47;
if(a[i]=='(')
aa[j++]=-40;
if(a[i]==')')
aa[j++]=-41;
if(a[i]=='=')
aa[j++]=-61;
//
printf("%lf\n",aa[j-1]);
}
}
i=0;
while(i<j)
{
if(aa[i]<0)
{
t=Is((int)(-1*p2.top()),(int)(-1*aa[i]));
if(t==1)
{
c=p2.top();
c=(int)(-c);
p2.pop();
x=p1.top();
p1.pop();
y=p1.top();
if(c=='+')
x=x+y;
if(c=='-')
x=y-x;
if(c=='/')
x=y/x;
if(c=='*')
x=x*y;
p1.top()=x;
}
if(t==-1)
p2.push((int)aa[i++]);
if(t==0)
{
p2.pop();
i++;
}
if(p2.size()==0)
break;
}
else
p1.push(aa[i++]);
}
printf("%.2lf\n",p1.top());
}
return 0;
}
int Is(int x,int y)
{
if(x=='+'&&y=='+')
return 1;
if(x=='+'&&y=='-')
return 1;
if(x=='+'&&y=='/')
return -1;
if(x=='+'&&y=='*')
return -1;
if(x=='+'&&y=='(')
return -1;
if(x=='+'&&y==')')
return 1;
if(x=='-'&&y=='+')
return 1;
if(x=='-'&&y=='-')
return 1;
if(x=='-'&&y=='/')
return -1;
if(x=='-'&&y=='*')
return -1;
if(x=='-'&&y=='(')
return -1;
if(x=='-'&&y==')')
return 1;
if(x=='*'&&y=='+')
return 1;
if(x=='*'&&y=='-')
return 1;
if(x=='*'&&y=='/')
return 1;
if(x=='*'&&y=='*')
return 1;
if(x=='*'&&y=='(')
return -1;
if(x=='*'&&y==')')
return 1;
if(x=='/'&&y=='+')
return 1;
if(x=='/'&&y=='-')
return 1;
if(x=='/'&&y=='/')
return 1;
if(x=='/'&&y=='*')
return 1;
if(x=='/'&&y=='(')
return -1;
if(x=='/'&&y==')')
return 1;
if(x=='('&&y=='+')
return -1;
if(x=='('&&y=='-')
return -1;
if(x=='('&&y=='/')
return -1;
if(x=='('&&y=='*')
return -1;
if(x=='('&&y=='(')
return -1;
if(x=='('&&y==')')
return 0;
if(x==')'&&y=='+')
return 1;
if(x==')'&&y=='-')
return 1;
if(x==')'&&y=='/')
return 1;
if(x==')'&&y=='*')
return 1;
if(x==')'&&y=='(')
return 1;
if(x==')'&&y==')')
return 1;
if(x=='='&&y=='=')
return 0;
if(x=='='&&y!='=')
return -1;
if(x!='='&&y=='=')
return 1;
}