http://acm.nyist.net/JudgeOnline/problem.php?pid=305
来源:互联网 发布:驱动人生mac版下载 编辑:程序博客网 时间:2024/04/23 22:52
去年省赛的一道题。。。有两个知识点值得注意:一个就是数字的入栈,一个就是特殊的测试数据,,
#include<string.h>#include<string>#include<stack>#include<algorithm>#include<stdlib.h>#include<iostream>using namespace std;stack<int>shu;stack<char>fu;string s;int cal(char ch,int x,int y){if(ch=='d') return (x+y);else if(ch=='n') return min(x,y);else if(ch=='x') return max(x,y);}void doit(){int second=shu.top(); shu.pop(); int first=shu.top(); shu.pop(); char ch=fu.top(); fu.pop(); int result=cal(ch,first,second); shu.push(result);}void solve(){string s1="";bool flag(false);for(int i=0;i<s.size();++i){ if(isdigit(s[i])) flag=true; else flag=false; if(flag) s1+=s[i]; else { if(s1!="") { int k=atoi(s1.data()); shu.push(k); } s1=""; if((s[i]=='d'&&s[i+1]=='d')||s[i]=='x'||s[i]=='n'||s[i]=='(') fu.push(s[i]); if(s[i]==')') {fu.pop(); doit();}}}if(!s1.empty()){ cout<<s1<<endl; return;}cout<<shu.top()<<endl;shu.pop();}int main(){ int T; cin>>T;while(T--){cin>>s;solve();}return 0;}
- http://acm.nyist.net/JudgeOnline/problem.php?pid=305
- http://acm.nyist.net/JudgeOnline/problem.php?pid=290
- http://acm.nyist.net/JudgeOnline/problem.php?pid=434
- http://acm.nyist.net/JudgeOnline/problem.php?pid=13
- http://acm.nyist.net/JudgeOnline/problem.php?pid=239
- http://acm.nyist.net/JudgeOnline/problem.php?pid=129
- http://acm.nyist.net/JudgeOnline/problem.php?pid=431
- http://acm.nyist.net/JudgeOnline/problem.php?pid=301
- http://acm.nyist.net/JudgeOnline/problem.php?pid=451
- http://acm.nyist.net/JudgeOnline/problem.php?pid=459
- http://acm.nyist.net/JudgeOnline/problem.php?pid=20
- http://acm.nyist.net/JudgeOnline/problem.php?pid=267
- http://acm.nyist.net/JudgeOnline/problem.php?pid=309
- http://acm.nyist.net/JudgeOnline/problem.php?pid=325
- http://acm.nyist.net/JudgeOnline/problem.php?pid=420
- http://acm.nyist.net/JudgeOnline/problem.php?pid=488
- http://acm.nyist.net/JudgeOnline/problem.php?pid=150
- http://acm.nyist.net/JudgeOnline/problem.php?pid=119
- douzi
- C++学习笔记之 II 读《我的第一本c++》
- 语义化你的HTML标签和属性
- sqlserver性能优化
- CSS命名及书写规范
- http://acm.nyist.net/JudgeOnline/problem.php?pid=305
- Oracle体系结构-参数文件
- 去掉Ubuntu10.04加密主目录的一种方法
- ASCII编码表
- 静态嵌套类和内部类的区别
- 0315surface在jni层显示
- Socket开发之通讯协议及处理
- C语言学习之路之六--------指针初学
- 192. Guilty consciences make man cowards. 做贼心虚