WAn次后的AC

//运算后的结果会溢出int
#include <cstdio>
#include <stack>
using namespace std;
const int MOD=10000;
int main()
{
stack<int> it;
stack<char> op;
int e;
char ch;
while(scanf("%d%c",&e,&ch)&&ch!='\n')
{
e%=MOD;
it.push(e);
if(op.empty())
{
op.push(ch);
}
else
{
char tp=op.top();

if(ch=='*'&&tp=='+')
{
op.push(ch);
}
else
{
op.pop();
int y=it.top();it.pop();
int x=it.top();it.pop();
int z;
if(tp=='+') z=x+y;
else z=x*y;
z%=MOD;
it.push(z);
op.push(ch);
}
}
}
it.push(e);
while(!op.empty())
{
char ch=op.top();op.pop();
int y=it.top();it.pop();
int x=it.top();it.pop();
int z;
if(ch=='+') z=x+y;
else z=x*y;
z%=MOD;
it.push(z);
}
int res=it.top();
res%=MOD;
printf("%d\n",res);
return 0;
}

0 条评论

目前还没有评论...

信息

ID
1849
难度
7
分类
(无)
标签
递交数
3574
已通过
763
通过率
21%
被复制
10
上传者