题目背景
蒟蒻HansBug在数学考场上,挠了无数次的头,可脑子里还是一片空白。
题目描述
好不容易啊,HansBug终于熬到了做到数学最后一题的时刻了,眼前是一堆杂乱的加减算式。显然成功就在眼前了。可是他脑细胞和RP已经消耗殆尽,所以这个重要的任务就交给你们啦。
输入格式
一行,包含一个字符串形式的加减法多项式(每一项数字范围为0-32767)。
输出格式
一个整数,为计算所得的结果(保证计算结果不会超过长整型范围)。
输入输出样例
输入 #1
1+2-3
输出 #1
0
说明/提示
字符串长度不超过60000
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<cstdio>
using namespace std;
int ans;
int c;
int main()
{
while(cin>>c)
ans+=c;
cout<<ans;
return 0;
}
====================================================
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<cstdio>
using namespace std;
int main(){
int ans;
cin>>ans;
int cache;
char c;
while(1){
if(scanf("%c",&c)==EOF){
break;
}
scanf("%d",&cache);
if(c=='+') ans+=cache;
if(c=='-') ans-=cache;
}
printf("%d",ans);
return 0;
}