显示代码纯文本
#include <cstdio>
int main()
{
freopen("expr2013.in","r",stdin);freopen("expr2013.out","w",stdout);
const int M = 10000;
char ch;
int product = 1, num = 0, ans = 0;
while ((ch = getchar()) != '\n')
{
if (ch == '*')
{
product = product * num % M;
num = 0;
}
else if (ch == '+')
{
ans = (ans + num * product) % M; //把乘法的最后一个因子也乘进去
product = 1;
num = 0;
}
else
{
num = (num * 10 + ch - '0') % M; // 数字也只保留 4 位,这样可以避免用 long long.
}
}
printf("%d\n", (ans + num * product) % M); // 最后不要忘了把最后一项加进答案
return 0;
}