Sicily 4960 Identity Checker
来源:互联网 发布:双色球软件破解版 编辑:程序博客网 时间:2024/06/17 16:36
直接用栈模拟,“-”顺序别弄错,不然会WA...
#include<iostream>#include<string>#include<cmath>#include<stack>using namespace std;int main() { int n; while (cin >> n && n) { stack<double> stk; string str; for (int i = 0; i < n; i++) { cin >> str; if (str == "x") { stk.push(2); } else if (str == "sin") { double temp = stk.top(); stk.pop(); stk.push(sin(temp)); } else if (str == "cos") { double temp = stk.top(); stk.pop(); stk.push(cos(temp)); } else if (str == "tan") { double temp = stk.top(); stk.pop(); stk.push(tan(temp)); } else if (str == "+") { double temp1 = stk.top(); stk.pop(); double temp2 = stk.top(); stk.pop(); stk.push(temp1 + temp2); } else if (str == "-") { double temp1 = stk.top(); stk.pop(); double temp2 = stk.top(); stk.pop(); stk.push(temp2 - temp1); } else if (str == "*") { double temp1 = stk.top(); stk.pop(); double temp2 = stk.top(); stk.pop(); stk.push(temp1 * temp2); } } if (fabs(stk.top()) < 0.00000001) { cout << "Identity" << endl; } else { cout << "Not an identity" << endl; } }}
0 0
- Sicily 4960 Identity Checker
- Sicily 4960. Identity Checker
- Gym100015 I Identity Checker 栈容器使用,数学
- identity
- @@IDENTITY
- @@IDENTITY
- @@identity
- Proxy Checker
- PKU_ACM_1035_Spell checker
- Checker Challenge
- Checker Challenge
- Spell checker
- 【usaco】 checker
- Larbin:checker
- USACO/checker
- POJ1035Spell Checker
- Checker Challenge
- Checker Challenge
- Android常见abd指令集
- ScrollView中的GridView ,解决不能滚动问题
- BackGroundWorker组件详解
- chrome添加扩展
- 5种连接方式
- Sicily 4960 Identity Checker
- Cocos2d-x 屏幕适配新解
- 解决CI框架因为开启XSS造成的乱码问题
- 订阅号也不易
- 适配器模式
- Sqlite query & rawQuery
- VIM实用使用技巧
- opencv——查找轮廓
- Android中LocalSocket使用