mxqz,re两点
查看原帖
mxqz,re两点
241817
Chancylaser楼主2021/11/27 19:09

数组开得很大了qwq

re on 2&10

#include<bits/stdc++.h>
using namespace std;
int n,cz[5005],k,len,x;
int fr[5005],kk,h;
string s;
long long zhan[5005];
bool pd;
const int SUM=1e9,NUM=-1e9;
void f(){
	len=0,h=0,pd=0;
	zhan[++len]=x;
	for(int i=1;i<=k;i++){
		if(cz[i]==1){
			zhan[++len]=fr[++h];
			if(fr[h]>SUM||fr[h]<NUM){
				pd=1;
				return;
			}
		}
		else if(cz[i]==2) len--;
		else if(cz[i]==3){
			int t=-zhan[len];
			zhan[len]=t;
			if(t>SUM||t<NUM){
				pd=1;
				return;
			}
		}
		else if(cz[i]==4){
			int t=zhan[len];
			zhan[++len]=t;
		}
		else if(cz[i]==5){
			int t1=zhan[len],t2=zhan[len-1];
			zhan[len-1]=t1;
			zhan[len]=t2;
		}
		else if(cz[i]==6){
			int t1=zhan[len],t2=zhan[len-1];
			len-=2;
			zhan[++len]=t1+t2;
			if(t1+t2>SUM||t1+t2<NUM){
				pd=1;
				return;
			}	
		}
		else if(cz[i]==7){
			int t1=zhan[len],t2=zhan[len-1];
			len-=2;
			zhan[++len]=t2-t1;	
		}
		else if(cz[i]==8){
			int t1=zhan[len],t2=zhan[len-1];
			len-=2;
			zhan[++len]=t1*t2;	
			if(t1*t2>SUM||t1*t2<NUM){
				pd=1;
				return;
			}
		}
		else if(cz[i]==9){
			int t1=zhan[len],t2=zhan[len-1];
			len-=2;
			zhan[++len]=t2/t1;
			if(t1==0){
				pd=1;
				return;
			}	
		}
		else if(cz[i]==10){
			int t1=zhan[len],t2=zhan[len-1];
			len-=2;
			zhan[++len]=t2%t1;	
			if(t1==0){
				pd=1;
				return;
			}
		}
	}
}
int main(){
	while(1){
		cin>>s;
		int qwq;
		if(s=="NUM") cin>>qwq,cz[++k]=1,fr[++kk]=qwq;
		else if(s=="POP") cz[++k]=2;
		else if(s=="INV") cz[++k]=3;
		else if(s=="DUP") cz[++k]=4;
		else if(s=="SWP") cz[++k]=5;
		else if(s=="ADD") cz[++k]=6;
		else if(s=="SUB") cz[++k]=7;
		else if(s=="MUL") cz[++k]=8;
		else if(s=="DIV") cz[++k]=9;
		else if(s=="MOD") cz[++k]=10;
		else break;
	}
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>x;
		f();
		if(pd==1||len!=1){
			cout<<"ERROR\n";
			continue;
		}
		cout<<zhan[len]<<endl;
	}
	return 0;
}
2021/11/27 19:09
加载中...