90第一个测试点不过
查看原帖
90第一个测试点不过
977630
java_death楼主2025/2/6 10:27

第一个测试点不过,但最后输出加上%M就过了,为什么?

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef tuple<ll,int,char> tp;
const int M=1e4;
stack<char> chr;
stack<ll> num;
string s;
tp read(int n){
	int i=n;
	ll x=0;
	for(;i<s.size()&&s[i]>='0'&&s[i]<='9';i++)x=x*10+s[i]-'0';
	if(i==s.size())return make_tuple(x,i,0);
	else return make_tuple(x,i,s[i]);
}
ll getn(){
	ll res=num.top();
	num.pop();
	return res;
}
int main(){
	cin>>s;
	for(int i=0;i<s.size();i++){
		tp rd=read(i);
		num.push(get<0>(rd));
		if(chr.size()&&chr.top()=='*'){
			chr.pop();
			ll n1=getn(),n2=getn();
			num.push(((n1%M)*(n2%M))%M);
		}if(get<2>(rd))chr.push(get<2>(rd));
		i=get<1>(rd);
	}
  while(chr.size()){
		chr.pop();
		ll n1=getn(),n2=getn();
		num.push((n1%M+n2%M)%M);
	}
  cout<<num.top();//就这行,改成cout<<num.top()%M就过了
	return 0;
}```
2025/2/6 10:27
加载中...