实在是想不出代码哪里有问题,测试样例太大没办法处理,手输数据没找到过出问题的反例,整了一晚上,枯了......
#include<iostream>
using namespace std;
long long judge,now,last,tot;
char x;
int main()
{
while((x=getchar())!='\r' and x!='\n' and x!=' ')
{
switch(x)
{
case '+':
{
if(last)
{
now*=last;
last=0;
}
tot+=now;
tot%=10000;
now=0;
break;
}
case '*':
{
if(last)
{
now*=last;
now%=10000;
}
last=now;
now=0;
break;
}
default :
{
now*=10;
now+=(x-'0');
break;
}
}
}
if(last)
{
now*=last;
now%=10000;
last=0;
}
tot+=now;
tot%=10000;
now=0;
cout<<tot;
}