-
Notifications
You must be signed in to change notification settings - Fork 0
/
201302.cpp
77 lines (77 loc) · 1.25 KB
/
201302.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include<stack>
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int main()
{
//freopen("a.in","r",stdin);
//freopen("a.out","w",stdout);
char a;
long long len=0,l,k,n1,n2;
stack<long long> num;
stack<char> hao;
while(cin>>a)
// {
// for(int i=0;i<l;i++)
{
if(a>='0'&&a<='9')
{
if(len==0)
num.push(int(a)-48);
else
{
k=num.top()%10000;
num.pop();
num.push((k*10%10000+int(a)-48)%10000);
}
len=1;
}
if(a=='+')
{
len=0;
while(!hao.empty()&&hao.top()=='*')
{
n1=num.top()%10000;
num.pop();
n2=num.top()%10000;
num.pop();
num.push(n1*n2%10000);
hao.pop();
// cout<<num.top()<<endl;
}
hao.push('+');
}
if(a=='*')
{
len=0;
hao.push('*');
}
}
while(!hao.empty())
{
if(hao.top()=='+')
{
n1=num.top()%10000;
num.pop();
n2=num.top()%10000;
num.pop();
num.push((n1+n2)%10000);
hao.pop();
// cout<<num.top()<<endl;
}
if(!hao.empty()&&hao.top()=='*')
{
n1=num.top()%10000;
num.pop();
n2=num.top()%10000;
num.pop();
num.push(n1*n2%10000);
hao.pop();
// cout<<num.top()<<endl;
}
}
cout<<num.top()%10000;
// }
return 0;
}