题目描述:
对于一个不存在括号的表达式进行计算
输入:
存在多种数据,,每组数据一行,表达式不存在空格
输出:
输出结果
样例输入: 6/2+3+3*4样例输出: 18来源:
2010年上海交通大学计算机研究生机试真题
#include<cstdio>using namespace std; int main(){char ch;int i,j,temp,a[200];while(scanf("%d",&temp)!=EOF){i=1;a[0]=0;a[1]=temp;while(scanf("%c",&ch)!=EOF && ch!='\n'){scanf("%d",&temp);if(ch=='-')a[++i]=-temp;else if(ch=='+')a[++i]=temp;else if(ch=='*')a[i]*=temp;else if(ch=='/')a[i]/=temp;}for(j=1;j<=i;++j)a[0]+=a[j];printf("%d\n",a[0]);}return 0;}/**************************************************************Problem: 1101User: CarvinLanguage: C++Result: AcceptedTime:0 msMemory:1020 kb****************************************************************/
停止每日在车水马龙的市井里忙碌的穿梭,