标签:
#include<cstdio> #include<cstring> char s[20]; int n,i,j,ans,symbol,a,l; int main(){ scanf("%d",&n); while(n--){ ans=symbol=0; while(scanf("%s",s)&&s[0]!=‘=‘){ if (s[0]>47){ a=0; l=strlen(s); for (i=0;i<l;i++) a=a*10+s[i]-48; if (symbol==0)ans=a; if (symbol==1)ans+=a; if (symbol==2)ans-=a; if (symbol==3)ans*=a; if (symbol==4)ans/=a; } if (s[0]==‘+‘)symbol=1; if (s[0]==‘-‘)symbol=2; if (s[0]==‘*‘)symbol=3; if (s[0]==‘/‘)symbol=4; } printf("%d\n",ans); } }
模拟,无法理解为何是从左往右算。。
SPOJ Problem 4452:Simple Arithmetics II
标签:
原文地址:http://www.cnblogs.com/moris/p/4328320.html