牛客网 小a的计算器
链接:
https://ac.nowcoder.com/acm/contest/317/A
来源:牛客网
题目描述
小a的数学基础实在太差了,以至于他只会用计算器算数。他的计算器比较特殊,只有+,−,×,/+, -, times, /+,−,×,/(即加减乘除)四种运算。
经过一番周折,小a终于算出了他想要的数,但是他却忘记了最初的数是什么。不过幸运的是他记下了整个操作序列,他想请你帮他算出最初的数
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 1e5+5;
#define ll long long int
ll num[maxn];
ll opt[maxn];
int main()
{
ll n,x;
while(cin>>n>>x)
{
for(int i=0;i<n;++i)
{
cin>>opt[i]>>num[i];
}
for(int i=n-1;i>=0;--i)
{
if(opt[i]==1)
{
x-=num[i];
}else if(opt[i]==2)
{
x+=num[i];
}else if(opt[i]==3)
{
x/=num[i];
}else if(opt[i]==4)
{
x*=num[i];
}
}
cout<<x<<endl;
}
return 0;
}