1 solutions
-
0
C++ :
#include <bits/stdc++.h> using namespace std; const int MOD = 10000; int num; char c; stack<int> stk; int main() { scanf("%d", &num); num %= MOD; stk.push(num); while ( (c = getchar()) != EOF ) { if (c != '*' && c != '+') break; scanf("%d", &num); num %= MOD; if (c == '+') { while (stk.size() > 1) { int a = stk.top(); stk.pop(); int b = stk.top(); stk.pop(); stk.push( (a + b) % MOD ); } stk.push(num); } else if (c == '*') { int a = stk.top(); stk.pop(); stk.push(a * num % MOD); } } while (stk.size() > 1) { int a = stk.top(); stk.pop(); int b = stk.top(); stk.pop(); stk.push( (a + b) % MOD ); } printf("%d\n", stk.top()); return 0; }
- 1
Information
- ID
- 9186
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By