使用壹個棧存儲運算符 最後運算符逐個出棧 進行相應的運算 不過壹定要註意 運算的優先級 還要註意要壹邊計算壹邊取摸
#include<cstdio>#include<cstring>
#include<cmath>
#include<iostream>
#include<cstdlib>
#include<algorithm>
using?namespace?std;
const?int?kela=1000010,momo=10000;
char?s[kela];
int?main()
{
freopen("t.in","r",stdin);
freopen("t.out","w",stdout);
int?i,a=1,b=0,ans=0;
gets(s);
for(i=0;i<strlen(s);++i)
switch(s[i])
{
case?'+':ans=(ans+a*b)%momo;a=1;b=0;break;
case?'*':a=a*b%momo;b=0;break;
default:b=(b*10+s[i]-'0')%momo;
}
printf("%d",(ans+a*b)%momo);
fclose(stdin);fclose(stdout);
return?0;
}