社区讨论

40 求调

P1981[NOIP 2013 普及组] 表达式求值参与者 1已保存回复 0

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
0 条
当前快照
1 份
快照标识符
@mdia4sek
此快照首次捕获于
2025/07/25 11:46
8 个月前
此快照最后确认于
2025/11/04 03:46
4 个月前
查看原帖
CPP
#include<bits/stdc++.h>
using namespace std;
int sum,ans,Mod=10000;
bool fl;
stack<int>num;
int main(){
	string s;
	cin>>s;
	int l=s.size();
	for(int i=0;i<l;i++){
		char c=s[i];
		if('0'<=c and c<='9')sum=sum*10+(c-'0');
		else{
			num.push(sum);
			sum=0;
			if(fl){
				int a=num.top();
				num.pop();
				int b=num.top();
				num.pop();
				num.push((a%Mod*b%Mod)%Mod);
				fl=0;
			}
			if(c=='*')fl=1;
		}
	}
	if(!fl)num.push(sum);
	while(!num.empty()){
		ans+=num.top();
		num.pop();
	}
	printf("%d",ans%Mod);
	return 0;
}
单栈做法,已投降

回复

0 条回复,欢迎继续交流。

正在加载回复...