水3_NYOJ_305
来源:互联网 发布:什么是好的相声知乎 编辑:程序博客网 时间:2024/05/01 03:45
3
add(1,2)
max(1,999)
add(min(1,1000),add(100,99))
求表达式的值,栈的使用!
#include<iostream>#include<cstring>#include<cstdio>#include<string>#include<stack>using namespace std;char b[1005];char aa[] = "add",bb[]="min",cc[]="max";struct node{ char d[100];};stack<node> S1;stack<double> S2;node p;double x,y;int g,w;int main(){ int t; scanf("%d",&t); while(t--) { while(!S1.empty())S1.pop(); while(!S2.empty())S2.pop(); scanf("%s",b); for(int i = 0; b[i];i++) { if(b[i] == 'a') { strcpy(p.d, aa); S1.push(p); i += 2; } else if(b[i] == 'm') { if(b[i+1] == 'i') { strcpy(p.d, bb); S1.push(p); i += 2; } else { strcpy(p.d, cc); S1.push(p); i += 2; } } else if(b[i] >= '0' && b[i] <= '9') { x = 0; while(b[i]>='0' && b[i] <= '9') { x = x*10+(b[i]-'0'); i++; } if(b[i]=='.') { g = 0,w = 1; i++; while(b[i]>='0' && b[i] <= '9') { g = (g*10)+(b[i]-'0'); w = w*10; i++; } x += (g*1.0/w); } i--; S2.push(x); } else if(b[i] == ')') { x = S2.top();S2.pop(); y = S2.top();S2.pop(); p = S1.top();S1.pop(); if(strcmp(p.d,aa)==0) { x += y; S2.push(x); } else if(strcmp(p.d,bb)==0) { x = x<y?x:y; S2.push(x); } else { x = x>y?x:y; S2.push(x); } } else { } } double ans = S2.top(); cout<<ans<<endl; } return 0;}
0 0
- 水3_NYOJ_305
- 似水年华_5/3
- 取得3升的水
- hdu水题习题集(3)
- 多校3 HDU6065 Questionnaire 水
- 水题你也过不了3
- 1.1.3 Friday the Thirteenth【水】
- 水水笔-续3(08/30)
- poj入门水题整理3
- hnust 1101(水): 实验3-3:统计素数个数
- 水
- 水
- 水
- 水
- 水
- 水
- 水
- 水
- DFS+二分_NYOJ_306
- C++构造函数和析构函数异常
- 设计模式之单例模式
- # WinForm开发系列 - Form/Window
- C++运算符及其重载问题
- 水3_NYOJ_305
- C++异常处理的理解
- Act with Prudence
- 我转载的文章
- Apply Functional Programming Principles
- 在ubuntu14上面安装docker
- 主流.Net的IOC框架性能测试比较
- Ask, “What Would the User Do?” (You Are Not the User)
- c++的boost库学习笔记