//这个表达式求值,要先算最小单元的数值,可以采用递归方式
CODE:
#include<stdio.h>
#include<iostream>
using namespace std;
int start;
char str[1010];
int minn(int a, int b)
{
return a < b ? a : b;
}
int maxn(int a, int b)
{
return a > b ? a : b;
}
int fun()
{
int v, n;
switch(str[start])
{
case ‘a‘: start+=3;return fun() + fun();
case ‘m‘:
start += 3;
if(str[start-2] == ‘i‘)
return minn(fun(), fun());
else return maxn(fun(), fun());
case ‘(‘:
case ‘,‘:
case ‘)‘: start++;return fun();
default :
sscanf(str+start, "%d%n", &v, &n);
start += n;
return v;
break;
}
}
int main()
{
int n;
cin >> n;
getchar();
while(n--)
{
start = 0;
gets(str);
printf("%d\n", fun());
}
return 0;
}