Quantcast
Channel: CSDN博客推荐文章
Viewing all articles
Browse latest Browse all 35570

nyist 305 表达式求值 (递归)

$
0
0

点击打开题目链接

#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 查看评论

Viewing all articles
Browse latest Browse all 35570

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>