-
题目描述:
-
对于一个不存在括号的表达式进行计算
-
输入:
-
存在多种数据,每组数据一行,表达式不存在空格
-
输出:
-
输出结果
-
样例输入:
-
6/2+3+3*4
-
样例输出:
-
18
-
来源:
#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: 1101
User: Carvin
Language: C++
Result: Accepted
Time:0 ms
Memory:1020 kb
****************************************************************/