对于一个不存在括号的表达式进行计算
输入描述:
存在多种数据,每组数据一行,表达式不存在空格
输出描述:
输出结果
示例1
输入
复制
6/2+3+3*4
输出
复制
18
#include <stdio.h>
#include <cstdio>
#include <string>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <set>
using namespace std;
int main(){
double t;
double a[1001];
while(scanf("%lf",&t)!=EOF)
{
double sum=0;
char ch;
int i=0;
a[0]=t;
while(scanf("%c",&ch)!=EOF&&ch!='\n')
{
double t2;
scanf("%lf",&t2);
if(ch=='+')
a[++i]=t2;
else if(ch=='-')
a[++i]=-t2;
else if(ch=='*')
a[i]*=t2;
else if(ch=='/')
a[i]/=t2;
}
for(int j=0;j<=i;j++)
sum+=a[j];
printf("%.0lf",sum);
}
}