zoukankan      html  css  js  c++  java
  • 洛谷P1449 后缀表达式 栈 模拟 字符串

    洛谷P1449 后缀表达式

    栈 模拟 字符串
    栈模拟一下 碰到 . 如果输入的是数字就把数字放进栈中

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <cmath>
     4 #include <cstdlib>
     5 #include <string>
     6 #include <algorithm>
     7 #include <iomanip>
     8 #include <iostream>
     9 using namespace std ; 
    10 
    11 char s[1011] ; 
    12 int l,top,x ; 
    13 int st[1011] ; 
    14 
    15 int main() 
    16 {
    17     scanf("%s",s+1) ; 
    18     l = strlen(s+1) ; 
    19     x = -1 ; 
    20     for(int i=1;i<=l;i++) 
    21     {
    22         if(s[ i ]=='.') {
    23             if(x!=-1) st[++top] = x ; 
    24             x = -1 ; 
    25             continue ;
    26         }
    27         if(s[ i ]>='0'&&s[ i ]<='9') 
    28         {
    29             if(x==-1) x = 0 ; 
    30             x = x*10+s[ i ]-48 ; 
    31         } 
    32         if(s[ i ]=='+') top-- ,st[top] = st[top] + st[top+1] ; 
    33         if(s[ i ]=='-') top-- ,st[top] = st[top] - st[top+1] ; 
    34         if(s[ i ]=='*') top-- ,st[top] = st[top] * st[top+1] ; 
    35         if(s[ i ]=='/') top-- ,st[top] = st[top] / st[top+1] ; 
    36         
    37     }
    38     printf("%d
    ",st[top] ) ; 
    39     
    40     return 0 ; 
    41 }
  • 相关阅读:
    09.非线性-指数增长模型
    08.多元线性回归模型
    07.线性回归模型
    06.齐普夫定律验证
    05.森林火灾模型
    04.沙堆模型
    03.优先链接模型
    02.中心极限定理验证
    centos6字符
    dns解析慢 修改的参数
  • 原文地址:https://www.cnblogs.com/third2333/p/6985325.html
Copyright © 2011-2022 走看看