40 求调
查看原帖
40 求调
1267232
limitlessly楼主2025/7/25 11:45
#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;
}

单栈做法,已投降

2025/7/25 11:45
加载中...