150. Evaluate Reverse Polish Notation
2016-04-30 15:41
441 查看
int evalRPN(vector<string>& tokens) { vector<int> memo; int res=0; for(auto i:tokens){ int temp=0; if(i=="+"||i=="-"||i=="*"||i=="/"){ int second = memo.back(); memo.pop_back(); int first = memo.back(); memo.pop_back(); if(i=="+") memo.push_back(first+second); else if(i=="-") memo.push_back(first-second); else if(i=="*") memo.push_back(first*second); else if(i=="/"){ memo.push_back(first/second); } } else memo.push_back(stoi(i)); } return memo.back(); }
这题太简单了没啥好说的。不过注意先pop出来的是first
相关文章推荐
- 自己实验lua
- lua面向对象封装及元表(metatable)性能测试
- 我理解的设计模式:单例模式
- LUA基本函数库
- Lua面向对象
- Lua模块处理
- Lua垃圾回收和弱引用
- Lua学习(六)元表和元方法
- Lua_第26章撰写 C 函数的技巧
- Ionic的项目结构(angluar js)
- Lua 5.2/5.3 热更新小结
- 记录lua的table转string一个问题
- 我理解的设计模式:工厂模式
- lua: pcall xpcall debug
- Lua_第25章 调用 C 函数
- C++与Lua5.3.2的相互调用
- Lua 中的string库(字符串函数库)总结
- RobotFrameWork(四)变量运算与Evaluate
- C++调用lua简单的例子
- Lua从入门到放弃--协同程序