1913: 小火山的计算能力

1913: 小火山的计算能力

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

Submit Status Web 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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值