#include <iostream> #include<string> using namespace std; int i; string s; int f() { i++; int x=0;while((s[i]==')'||s[i]==',')&&i<s.length()) i++; while(s[i]>='0'&&s[i]<='9'&&i<s.length()) { x=x*10+(s[i]-'0'); if(s[i+1]>='0'&&s[i+1]<='9') i++; else return x; } if(s[i]=='a'&&i<s.length()) { i+=3; return f()+f(); } if(s[i]=='m'&&s[i+1]=='i'&&i<s.length()) { i+=3; return min(f(),f()); } if(s[i]=='m'&&s[i+1]=='a'&&i<s.length()) { i+=3; return max(f(),f()); } } int main() { int t,n,j,ans,x; cin>>t; while(t--) { cin>>s;i=-1; cout<<f()<<endl; } return 0; }
作者:liang5630 发表于2013-5-9 23:47:29 原文链接
阅读:2 评论:0 查看评论