2 solutions
-
1
#include <iostream> #include <stack> using namespace std; int main(){ int a,b,ans=0; char op; cin>>a; stack<int>st; st.push(a); while(cin>>op>>b){ b%=10000; if(op=='+')st.push(b); else if(op=='*'){ ans=st.top(); st.pop(); ans=ans*b; st.push(ans%10000); } } ans=0; while(!st.empty()){ ans+=st.top(); st.pop(); ans%=10000; } cout<<ans<<endl; return 0; }
-
0
#include<bits/stdc++.h> using namespace std; string m; long long s1[5000000],n=0; char s2[500000]; int main(){ cin>>m; int x=1,y=1; for(int i=0;i<m.size();i++){ if(m[i]>='0'&&m[i]<='9'){ s1[x]=s1[x]*10+m[i]-'0'; } else{ x++; s2[y++]=m[i]; } } for(int i=1;i<y;i++){ if(s2[i]=='*'){ s1[i+1]=s1[i]*s1[i+1]%10000; s1[i]=0; } } for(int i=1;i<=x;i++){ n+=s1[i]; } cout<<n%10000; return 0; }
- 1
Information
- ID
- 729
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 7
- Tags
- # Submissions
- 132
- Accepted
- 33
- Uploaded By