表达式求值

表达式求职

输入输出样例

输入

1:

1+1*3+4

2:

1+1234567890*1

3:

1+1000000003*1

输出

1:

8

2:

7891

3:

4

 1 #include<iostream>
 2 
 3 #include<stdio.h>
 4 
 5 using namespace std;
 6 
 7 int t,s[100005],ans;
 8 
 9 char f[100005];
10 
11 int main(){
12 
13    while(cin>>s[++t])f[t]=getchar(),s[t]%=10000;
14 
15    for(int i=1;i<t;++i)
16 
17        if(f[i]=='*')
18 
19            for(int j=i;j<t;++j)
20 
21                if(f[j]=='*')
22 
23                    s[i]*=s[j+1],s[i]%=10000,s[j+1]=0;
24 
25                else break;
26 
27    for(int i=1;i<=t;++i)
28 
29        ans+=s[i],ans%=10000;
30 
31    cout<<ans;
32 
33 }
原文地址:https://www.cnblogs.com/__Kgds/p/9488060.html