您的位置:首页 > 其它

1913: 小火山的计算能力

2016-08-10 19:23 806 查看

1913: 小火山的计算能力

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 444  Solved: 107

SubmitStatusWeb
Board

Description

别人说小火山的计算能力不行,小火山很生气,于是他想证明自己,现在有一个表达式,他想计算出来。

Input

首先是一个t(1<=20)表示测试组数。然后一个表达式,表达式长度不超过200,只有加法和减法,并且保证第一个字符不会是运算符号,最终结果小于2^63-1。

Output

输出运算结果。

Sample Input

2

1+1

2+1-1

Sample Output

2

2

HINT

Source

zzuli

模拟队列

#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
int main()
{
long long a;
char s[210];
int t;
scanf("%d",&t);
while(t--)
{

scanf("%s",&s);
int l=strlen(s);
queue<long long>q1;
queue<char>q2;
for(int i=0;i<l;)
{  a=0;
while(s[i]>='0'&&s[i]<='9')
{
a=a*10+s[i]-'0';
i++;
}
q1.push(a);
if(i<l)
{
q2.push(s[i]);
i++;
}
}
long long sum,aa;char bb;
sum=q1.front();q1.pop();
while(!q2.empty())
{
aa=q1.front();q1.pop();
bb=q2.front();q2.pop();
if(bb=='+')
sum+=aa;
else
sum-=aa;
}
printf("%lld\n",sum);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: