AcWing 454. 表达式求值
原题链接
中等
作者:
一只迷路的小A
,
2021-02-03 15:52:11
,
所有人可见
,
阅读 442
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
long long int ans,tmpx,tmp;
ans=0;
tmpx=1;
tmp=0;
char buf;
while(scanf("%c",&buf)==1&&buf!=10)
{
if(buf-'0'<=9&&buf-'0'>=0)
{
tmp*=10;
tmp+=buf-'0';
}
if(buf=='+')
{
if(tmpx!=1){tmpx*=tmp;tmp=0;ans=ans%10000;ans+=tmpx%10000;ans=ans%10000;tmpx=1;}
else
{ ans=ans%10000;
ans+=tmp%10000;
ans=ans%10000;
tmp=0;
}
}
if(buf=='*'){
tmpx*=tmp;
tmpx=tmpx%10000;
ans=ans%10000;
tmp=0;
}
}
if(tmpx!=1){tmpx*=tmp;ans+=tmpx;}
else{ans+=tmp%10000;ans=ans%10000;}
cout<<ans%10000;
return 0;
}
这么菜还来发题解?
三峰皮了