设为首页 加入收藏

TOP

LeetCode之逆波兰式求解
2015-07-20 17:50:29 来源: 作者: 【 】 浏览:3
Tags:LeetCode 波兰 求解

计算逆波兰式子:

有效的操作只有 +, -, *, /. 每一个输入不是一个整数就是一个操作符。

Some examples:

  ["2", "1", "+", "3", "*"] -> ((2 + 1) * 3) -> 9
  ["4", "13", "5", "/", "+"] -> (4 + (13 / 5)) -> 6

#include
   
     #include
    
      #include
     
       using namespace std; const int Max=100; bool isInt(const string str) { if(str[0]=='+'||(str[0]=='-'&&str.size()==1)||str[0]=='*'||str[0]=='/') return false; else return true; } int toInt(string str) { int re=0; //cout<<"str: "<
      
        &tokens) { double values[Max]={0}; int k=0; vector
       
         oper; double result=0; for(int i=0;i
        
          token(str,str+5); cout<
         
        
       
      
     
    
   

代码中用数组模拟类一个栈的操作。

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C++变量的存储类别与作用域 下一篇hdu 4940 无源汇有上下界最大流

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·switch520最新的地址 (2025-12-24 19:19:41)
·微信聊天功能使用了 (2025-12-24 19:19:39)
·websocket和普通的so (2025-12-24 19:19:36)
·Python中文网 - 人生 (2025-12-24 18:49:47)
·【整整648集】这绝对 (2025-12-24 18:49:44)