zoukankan      html  css  js  c++  java
  • 计蒜客:表达式求值

     

    这道题,想了一早上。只可意会不可言传。

    需要注意的点:1.输入的时候ch==10为回车。

    while(scanf("%c",&ch)&&ch!=10)
    {
    
    }

    2.  

    #include <iostream>
    #include <cstdio>
    using namespace std;
    const int mod = 1e4;
    int main()
    {
        char ch;
        int tmp=0,tmpx=1,ans=0;
        while(scanf("%c",&ch)&&ch!=10)
        {
            if(ch>='0'&&ch<='9')
            {
                tmp=tmp*10+ch-'0';
            }else if(ch=='+'){
                if(tmpx!=1)
                {
                    tmpx=(tmpx*tmp)%mod;
                    ans=(ans+tmpx)%mod;
                    tmpx=1;
                    tmp=0;
                }else{
                    ans=(ans+tmp)%mod;
                    tmp=0;
                }
            }else if(ch=='*'){
                tmpx=(tmpx*tmp)%mod;
                tmp=0;
            }
        }
        if(tmpx!=1){
            tmpx=(tmpx*tmp)%mod;
            ans=(ans+tmpx)%mod;
        }else{
            ans=(ans+tmp)%mod;
        }
        cout<<ans<<endl;
        return 0;
    }
    
  • 相关阅读:
    webkit 技术内幕 笔记 二
    webkit 技术内幕 笔记 一
    javascript 权威指南1
    正则
    react-virtualized
    移动端字体
    vue 学习3
    vue 学习2
    vue 学习1
    移动端display:flex
  • 原文地址:https://www.cnblogs.com/qie-wei/p/12094114.html
Copyright © 2011-2022 走看看