全RE求解答,宣关
查看原帖
全RE求解答,宣关
1054621
shaoxqy楼主2025/7/2 17:39

大佬们列举几个造成RE的原因即可,如果可以找出代码问题,则感之不尽。

#include<iostream>
#include<cstdlib>
#include<vector> 
using namespace std;
//定义区——————————————————————————
int n,m,nop,point=1;
int order[15]{0,1,2,3,4,5,6,7,8,9,10};
char cardpool[5000];

struct pig{
	char id;//真实身份 主猪M 忠猪Z 反猪F
	int hp=4;//血量 
	int hand=4;//手牌数量 
	int card=0;//遍历牌序 
	int type=0;//已明身份0=无,1=反,2=忠,3=主,4=类 
	bool tool=0;//0=无,1=有AK-47
	bool kill=1;//0=已经用了,1=没用	
	vector<char>handcard; 
}p[15];

int _length(int x){
	if(x>nop){
		return x-nop;
	}
	return x;
}

void _delete(int x,int y){//x为人物序号,y为第y张手牌 
	p[x].handcard.erase(p[x].handcard.begin()+y);
	p[x].hand--;
	p[x].card--;
} 

void _end(){
	for(int i=1;i<=n;i++){
		if(order[i]<=0){
			cout<<"DEAD"<<endl;
		}
		else{
			for(int j=0;j<p[order[i]].hand;j++){
				cout<<p[i].handcard.at(j)<<" ";
			}
			cout<<endl;			
		}
	}
//	while(point>=m){
//		cout<<cardpool[point]<<" ";
//		point++;
//	}
	abort();
}

bool ZP(){
	int total=1;
	for(int i=2;i<=nop;i++){
		if(p[i].id='Z'){
			total++;
		}
	}
	if(total==nop){
		return true;
	}
	return false;
}

void end(){
	if(order[1]<=0){
		cout<<"FP"<<endl;
		_end(); 
	}
	if(ZP()){
		cout<<"MP"<<endl;
		_end();
	}
	return;
}

char die(int x){
	order[x]=0;
	for(int i=x;i<=n;i++){
		order[i]--;
	}
	for(int i=x;i<=nop;i++){
		p[i]=p[i+1];
	}
	nop--;
	end();
	return p[x].id;
}

bool _find(int x,char y){
	for(int i=1;i<=p[x].hand;i++){
		if(p[x].handcard.at(i)==y){
			_delete(x,i);
			return true;
		}
	}
	return false;
}
//被动动作区————————————————————————
void lost(){
	p[1].handcard.clear();
	p[1].hand=0;
}

bool reply_p(int x){//x为人物序号
	if(_find(x,'P')){
		return true;
	}
	return false;
}

char reply_d(int x){//x为人物序号
	if(_find(x,'D')){
		return 0;
	}
	if(!p[x].hp--){
		if(reply_p(x)){
			p[x].hp++;
		}
		else{
			return die(x);
		}
	}
	return 0;
}

char reply_k(int x,int y,char z){//x为人物序号,y为来源 
	if(z=='F'){
		if(p[x].id=='Z'&&p[y].type==3){
			if(!p[x].hp--){
				if(reply_p(x)){
					p[x].hp++;
				}
				else{
					return die(x);
				}
			}
		}
	}
	if(_find(x,'K')){
		return '0';
	}				
	if(!p[x].hp--){
		if(reply_p(x)){
			p[x].hp++;
		}
		else{
			return die(x);
		}
	}
	return '1';
}

bool _reply_j(int x){//x为无懈来源 
	for(int i=x;i<=nop;i++){
		if((p[x].type==3||p[x].type==2)&&(p[i].id=='F')){
			if(_find(x,'J')){
				p[i].type==1;
				if(_reply_j(i)){
					return false;
				}
				return true; 
			}
		}
		if((p[x].type==1||p[x].type==4)&&p[i].id=='M'){
			if(_find(x,'J')){
				if(_reply_j(i)){
					return false;
				}
				return true; 
			}
		}
		if(p[x].type==1&&p[x].id=='Z'){
			if(_find(x,'J')){
				if(_reply_j(i)){
					return false;
				}
				return true; 
			}
		}
	}
	for(int i=1;i<x;i++){
		if((p[x].type==3||p[x].type==2)&&(p[i].id=='F')){
			if(_find(x,'J')){
				p[i].type==1;
				return true; 
			}
		}
		if((p[x].type==1||p[x].type==4)&&p[i].id=='M'){
			if(_find(x,'J')){
				return true; 
			}
		}
		if(p[x].type==1&&p[x].id=='Z'){
			if(_find(x,'J')){
				return true; 
			}
		}
	}
	return false;
}

bool reply_j(int x,int y){//x为目标,y为来源 
	for(int i=y;i<=nop;i++){
		if((p[x].type==3||p[x].type==2)&&(p[i].id=='Z'||p[i].id=='M')){
			if(_find(x,'J')){
				if(!p[i].type==3){
					p[i].type==2;
				}
				if(_reply_j(i)){
					return false;
				}
				return true; 
			}
		}
		if(p[x].type==1&&p[i].id=='F'){
			if(_find(x,'J')){
				p[i].type==2;
				if(_reply_j(i)){
					return false;
				}
				return true; 
			}
		}
	}
	for(int i=1;i<y;i++){
		if((p[x].type==3||p[x].id=='Z')&&(p[i].type==3||p[i].id=='M')){
			if(_find(x,'J')){
				if(!p[x].type==3){
					p[i].type==2;
				}
				if(_reply_j(i)){
					return false;
				}
				return true; 
			}
		}
		if(p[x].type==1&&p[i].id=='F'){
			if(_find(x,'J')){
				if(p[x].type=1){
					p[i].type==2;
				}
				if(_reply_j(i)){
					return false;
				}
				return true; 
			}
		}
	}
	return false;
}
//主动动作区————————————————————————
void get(int x,int y){//x为人物序号,y为牌数 
	for(int i=1;i<=y;i++){
		p[x].handcard.push_back(cardpool[point]);
		p[x].hand++;	
		if(!point==m){
			point++;
		}		
	} 
}
 
int use_p(int x,int y){//x为人物序号,y为第y张手牌 
	if(p[x].hp<4){
		p[x].hp++;
		_delete(x,y);
		return 1;
	}
	return 0;
}

int use_k(int x,int y){//x为人物序号,y为第y张手牌 
	if(p[x].id='M'){
		if(p[2].type==4||p[2].type==1){
			char a=reply_d(2);
			if(a='F'){
				get(x,3);
			}
			if(a='Z'){
				lost();
			}	
			p[x].kill=0;
			_delete(x,y); 
		}
		else if(p[nop].type==4||p[nop].type==1){
			if(reply_d(nop)){
				get(x,3);
			}
			p[x].kill=0; 
			_delete(x,y);
		}
	}
	if(p[x].id='F'){
		if(x==2||x==nop){
			reply_d(1);
			p[x].kill=0;
			_delete(x,y); 
		}
		else if(p[x-1].type=2){
			reply_d(x-1);
			p[x].kill=0;
			_delete(x,y); 
		}
		else if(p[x+1].type=2){
			reply_d(x+1);
			p[x].kill=0;
			_delete(x,y); 
		}
	}
	if(p[x].id='Z'){
		if(p[x-1].type=1){
			if(reply_d(x-1)){
				get(x,3);
			}
			p[x].kill=0;
			_delete(x,y); 
		}
		else if(p[x+1].type=1){
			if(reply_d(x+1)){
				get(x,3);
			}
			p[x].kill=0;
			_delete(x,y); 
		}
	}
}

void use_f(int x,int y){//x为人物序号,y为第y张手牌
	if(p[x].id='M'){
		for(int i=2;i<=nop;i++){
			if(p[i].type==1||p[i].type==4){
				int j=1;
				char a;
				_delete(x,y);
				if(reply_j(i,1)){
					return;
				}
				while(j){
					if(j%2==1){
						a=reply_k(i,x,'Z');
						if(a=='Z'){
							lost();
							j=0;
						}
						if(a=='F'){
							get(x,3);
							j=0;
						}
						if(a=='1'){
							j=0;
						}
					}
					else{
						a=reply_k(x,i,'Z');
						if(a=='F'){
							get(x,3);
							j=0;
						}
						if(a=='1'){
							j=0;
						}
					}
					j++;
				}
				return;
			}
		}	
	}
	if(p[x].id='F'){
		int j=1;
		char a;
		_delete(x,y);
		if(reply_j(1,x)){
			return;
		}
		while(j){
			if(j%2==1){
				a=reply_k(1,x,'Z');
				if(a=='1'){
					j=0;
				}
			}
			else{
				a=reply_k(x,1,'Z');
				if(a=='F'){
					get(x,3);
					j=0;
				}
				if(a=='1'){
					j=0;
				}
			}
			j++;
		}
	}
	if(p[x].id='Z'){
		for(int i=x+1;i<=nop;i++){
			if(p[i].type==1){
				int j=1;
				char a;
				_delete(x,y);
				if(reply_j(i,x)){
					return;
				}
				while(j){
					if(j%2==1){
						a=reply_k(i,x,'Z');
						if(a=='F'){
							get(x,3);
							j=0;
						}
						if(a=='1'){
							j=0;
						}
					}
					else{
						a=reply_k(x,i,'Z');
						if(a=='1'){
							j=0;
						}
					}
					j++;
				}
				return;
			}
		}
		for(int i=1;i<x;i++){
			if(p[i].type==1){
				int j=1;
				char a;
				_delete(x,y);
				if(reply_j(i,x)){
					return;
				}
				while(j){
					if(j%2==1){
						a=reply_k(i,x,'Z');
						if(a=='F'){
							get(x,3);
							j=0;
						}
						if(a=='1'){
							j=0;
						}
					}
					else{
						a=reply_k(x,i,'Z');
						if(a=='1'){
							j=0;
						}
					}
					j++;
				}
				return;
			}
		}
	}
	return;
}

void use_n(int x,int y){//x为人物序号,y为第y张手牌
	_delete(x,y);
	for(int i=x+1;i<=nop;i++){
		if(reply_j(i,x)){
			break;
		}
		char a;
		a=reply_k(x,i,'N');
		if(a=='Z'&&x==1){
			lost();
		}
		if(a=='F'){
			get(x,3);
		}
	}
	for(int i=1;i<x;i++){
		if(reply_j(i,x)){
			break;
		}
		char a;
		a=reply_k(x,i,'N');
		if(a=='Z'&&x==1){
			lost();
		}
		if(a=='F'){
			get(x,3);
		}
	}
}

void use_w(int x,int y){//x为人物序号,y为第y张手牌
	_delete(x,y);
	for(int i=x+1;i<=nop;i++){
		if(reply_j(i,x)){
			break;
		}
		char a;
		a=reply_d(i);
		if(a=='Z'&&x==1){
			lost();
		}
		if(a=='F'){
			get(x,3);
		}
	}
	for(int i=1;i<=x;i++){
		if(reply_j(i,x)){
			break;
		}
		char a;
		a=reply_d(i);
		if(a=='Z'&&x==1){
			lost();
		}
		if(a=='F'){
			get(x,3);
		}
	}
}

void use_z(int x,int y){
	_delete(x,y);
	p[x].tool=1;
}
//游戏运行区————————————————————————
void round(int x){
	get(x,2);
	p[x].card=0;
	while(p[x].card<=p[x].hand){
		if(p[x].handcard.at(p[x].card)='P'){
			use_p(x,p[x].card);
		}
		if(p[x].handcard.at(p[x].card)='K'){
			if(p[x].kill||p[x].tool){
				use_k(x,p[x].card);
			}
		}
		if(p[x].handcard.at(p[x].card)='F'){
			use_f(x,p[x].card);
		}
		if(p[x].handcard.at(p[x].card)='N'){
			use_n(x,p[x].card);
		}
		if(p[x].handcard.at(p[x].card)='W'){
			use_w(x,p[x].card);
		}
		if(p[x].handcard.at(p[x].card)='Z'){
			use_z(x,p[x].card);
		}
		p[x].card++;
	}
}
 
void begin(){
	for(int i=1;i<=nop;i++){
		round(i);
	}
}

int main(){
	cin>>n>>m;
	nop=n;
	p[1].type=3;
	char a;
	for(int i=1;i<=n;i++){
		for(int j=0;j<=3;j++){
			cin>>a;
			p[i].handcard.push_back(a);
		}
	}
	for(int i=1;i<=m;i++){
		cin>>cardpool[i];
	}
	while(true){
		begin();
	} 
	return 0;
} 
2025/7/2 17:39
加载中...