社区讨论
各位大佬,20求调
P1981[NOIP 2013 普及组] 表达式求值参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @mhjhc78c
- 此快照首次捕获于
- 2025/11/04 02:34 4 个月前
- 此快照最后确认于
- 2025/11/04 02:34 4 个月前
CPP
#include <bits/stdc++.h>
using namespace std;
stack<long long>st;
int main () {
char a;
int x=0, flag=0;
while(cin >> a) {
if(a >= '0' && a <= '9') {
x = x*10+(a-'0');
}
if(a == '+') {
if(flag == 1) {
long long t=st.top()*x;
st.pop();
st.push(t);
flag = 0;
x = 0;
} else {
st.push(x);
x = 0;
}
}
if(a == '*') {
if(flag == 0) {
st.push(x);
x = 0;
flag = 1;
} else {
long long t=st.top()*x;
st.pop();
st.push(t);
x= 0;
}
}
}
long long sum=0;
if(flag == 1 && x != 0) {
int y = st.top()*x;
st.pop();
st.push(y);
} else if(flag == 0 && x != 0){
st.push(x);
}
while (st.empty() != 1) {
sum += st.top();
st.pop();
}
cout << sum%10000;
return 0;
}
回复
共 0 条回复,欢迎继续交流。
正在加载回复...