40pts RE求调
查看原帖
40pts RE求调
1162093
jimmy0926楼主2024/5/8 19:15

结果有点可怕

#include <bits/stdc++.h>
#define uns unsigned
using namespace std;
uns x;
uns ans;
char ch,op='\0';
stack <uns> sta;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	while(cin>>ch)
	{
		if(isdigit(ch))
		{
			x=(x*10+ch-'0')%10000;
			continue;
		}
		sta.push(x);
		x=0;
		op=(op=='\0' ? ch:op);
		if(op=='*')
		{
			uns long long a,b;
			a=sta.top();
			sta.pop();
			b=sta.top();
			sta.pop();
			(a*=b)%=10000;
			sta.push(a);
		}
		op=ch;
	}
	sta.push(x);
	x=0;
	op=(op=='\0' ? ch:op);
	if(op=='*')
	{
		uns long long a,b;
		a=sta.top();
		sta.pop();
		b=sta.top();
		sta.pop();
		(a*=b)%=10000;
		sta.push(a);
	}
	while(sta.size())
	{
		(ans+=sta.top())%=10000;
		sta.pop();
	}
	cout<<ans;
	return 0;
}
2024/5/8 19:15
加载中...