题目大意
表示开门时已有的数量,表示接下来有组事件,表示加或减,表示加或减的数量,求关门前剩余的数量。
题目思路
如果为减号,那么就减去现在的数量,否则加上现在的数量 。
Code
#include<bits/stdc++.h>
using namespace std;
int D,Q;
int main(){
cin>>D>>Q;
while(Q--){
int n;
char a;
cin>>a>>n;
if(a=='-'){
D-=n;
}
else D+=n;
}
cout<<D;
return 0;
}