小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;
}

猜你喜欢

转载自blog.csdn.net/a1097304791/article/details/86624106