Description
别人说小火山的计算能力不行,小火山很生气,于是他想证明自己,现在有一个表达式,他想计算出来。
Input
首先是一个t(1<=20)表示测试组数。然后一个表达式,表达式长度不超过200,只有加法和减法,并且保证第一个字符不会是运算符号,最终结果小于2^63-1。
Output
输出运算结果。
Sample Input
2
1+1
2+1-1
Sample Output
2
2
#include<cstdio>
#include<string.h>
int main()
{
int t; scanf("%d",&t); while(t--)
{
long long i=,sum=,j; char c,str[]; scanf("%s",&str); int len=strlen(str); while(str[i]>='' && str[i]<='')
{
sum=sum*+str[i]-'';
i++;
} for(j = i ; j < len ; )
{
if(str[j] == '+')
{
c='+';
}
else
{
c='-';
}
j++; long long a=; while(str[j]>='' && str[j]<='')
{
a=a*+str[j]-'';
j++;
} if(c == '+')
{
sum+=a;
} else
{
sum-=a;
}
}
printf("%lld\n",sum);
}
}