nyoj305-表达式求值(栈。。dfs)
2017-11-25 20:49
471 查看
题目来源:http://acm./problem.php?pid=305
题意
求表达式的值。思路
利用深搜回溯的性质,模拟栈,,,代码
#include<cmath> #include<stack> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef long long LL; const int INF=0x3f3f3f3f; int i; char str[1000+10]; int dfs() { int x=0,a,b; while(str[i]==','||str[i]==')') i++; if(str[i+1]=='d') { i+=4; return dfs()+dfs(); } if(str[i+1]=='a') { i+=4; a=dfs(); b=dfs(); return a>b?a:b; } if(str[i+1]=='i') { i+=4; a=dfs(); b=dfs(); return a<b?a:b; } while(str[i]>='0'&&str[i]<='9') x=x*10+str[i++]-'0'< 4000 /span>; return x; } int main() { int T; scanf("%d",&T); while(T--) { scanf("%s",str); i=0; printf("%d\n",dfs()); } }
相关文章推荐
- NYOJ-305-表达式求值(第四届河南省程序设计大赛C题(模拟+栈||递归)(sscanf函数的应用))
- nyoj 305 表达式求值 栈,递归(switch)和数组
- NYOJ-305-表达式求值-2013年8月8日10:44:12
- NYOJ-305 表达式求值(模拟)
- NYOJ 305 表达式求值
- nyoj305 表达式求值(递归)
- NYOJ305 表达式求值
- nyoj 305 表达式求值 (栈实现)
- NYOJ 305-表达式求值【模拟】
- NYOJ305 表达式求值
- nyoj 305 表达式求值
- 表达式求值(nyoj 305)
- nyoj305_表达式求值
- NYOJ-305-表达式求值
- NYOJ305_表达式求值
- nyoj 305 表达式求值
- NYOJ 305 表达式求值 (简单栈应用)
- NYOJ 305 表达式求值
- NYOJ 305 表达式求值(递归)
- NYOJ 305 表达式求值