小a的计算器(牛客)
简单模拟题, 直接逆序处理结果即可
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <stdlib.h>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
using namespace std;
#define ms(x, n) memset(x,n,sizeof(x));
typedef long long LL;
const LL maxn = 1e6+10;
int main()
{
int n;
LL X, tmp = 1; //tmp储存除数
cin >> n >> X;
while(n--){
int opt;
LL x;
cin >> opt >> x;
if(opt==1) X -= x;
else if(opt==2) X += x;
else if(opt==3){
if(X%x==0) X/=x;
else tmp*=x;
if(X%tmp==0 && tmp!=1) X/=tmp, tmp = 1;
}
else if(opt==4) X *= x;
}
if(X%tmp==0 && tmp!=1) X/=tmp;
cout << X << endl;
return 0;
}