• UVAlive 6833 Miscalculation 字符串处理


    去年省选的题

    因为卡了这道题再加上队友占机时 省选第一天华丽爆零了

    用事实证明了1+1+1<1的事实

    毕竟下半年单挑了东北赛名额 省赛打不出来名额就真的就不怪我了(摔

    现在有拿出来做 长个记性 希望今年省选可以卷土重来

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 
     4 int way(char str[]) //
     5 {
     6     int ans=str[0]-'0';
     7     int now=1;
     8     while(str[now])
     9     {
    10         if(str[now]=='*')
    11         {
    12             now++;
    13             ans*=str[now]-'0';
    14         }
    15         else
    16         {
    17             now++;
    18             ans+=str[now]-'0';
    19         }
    20         now++;
    21     }
    22     return ans;
    23 }
    24 
    25 int way1(char str[])
    26 {
    27     int now=0;
    28     stack<int>st;
    29     st.push(str[now++]-'0');
    30     while(str[now])
    31     {
    32         int num=str[now+1]-'0';
    33         if(str[now]=='+')
    34         {
    35             st.push(num);
    36         }
    37         else
    38         {
    39             int tmp=st.top();
    40             st.pop();
    41             st.push(tmp*num);
    42         }
    43         now+=2;
    44     }
    45     int ans=0;
    46     while(!st.empty())
    47     {
    48         ans+=st.top();
    49         st.pop();
    50     }
    51     return ans;
    52 }
    53 
    54 int main()
    55 {
    56     char str[20];
    57     while(~scanf("%s",str))
    58     {
    59         int ans;
    60         scanf("%d",&ans);
    61         int x=way(str);
    62         int y=way1(str);
    63         if(x==ans&&y==ans) printf("U
    ");
    64         else if(x==ans) printf("L
    "); //
    65         else if(y==ans) printf("M
    ");
    66         else printf("I
    ");
    67     }
    68     return 0;
    69 }
    70 /*
    71 
    72 1+2*3+4
    73 11
    74 1+2*3+4
    75 13
    76 3
    77 3
    78 1+2*3+4
    79 9
    80 
    81 */
  • 相关阅读:
    查看进程的pid和ppid
    多进程《二》开启进程的两种方式
    多进程《一》进程理论
    并发编程《二》操作系统介绍2
    并发编程《一》操作系统介绍1
    Google浏览器历史版和下载地址
    python爬取淘宝排名
    字符编码
    hashlib
    离散数学
  • 原文地址:https://www.cnblogs.com/general10/p/6287769.html
Copyright © 2020-2023  润新知