CCF篇:201512-2 消除类游戏

#include<iostream>
using namespace std;
#define N 31
#define M 31
int a[M][N];
int b[M][N];
int c[M][N];
void row(int a[M][N]){

	for(int i=0;i<M;i++){
		int temp=-1,count=1;	
	    for(int j=0;j<N;j++){
	    	if(a[i][j]==temp&&a[i][j]!=0){
	    		count++;
			}else{
				if(count>=3){
					for(int k=j-count;k<j;k++){
						a[i][k]=0;
					}
				}
				temp=a[i][j];
				count=1;
			}	
		}
		}
}

void col(int a[M][N]){
	
	for(int i=0;i<N;i++){
          int temp=-1,count=1;
	    for(int j=0;j<M;j++){

	    	if(a[j][i]==temp&&a[j][i]!=0){
	    		count++;
			}else{
				if(count>=3){
					for(int k=j-count;k<j;k++){
						a[k][i]=0;
					}
				}
				temp=a[j][i];
				count=1;
			}
		}
		}
}
int main(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
	    	cin>>a[i][j];
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
	    	b[i][j]=a[i][j];
		}
	}
	row(a);
	col(b);
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			
			if(a[i][j]!=b[i][j]){
				c[i][j]=0;
			}else if(a[i][j]==b[i][j]){
				c[i][j]=b[i][j];
			}
			
		}
	}  
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
	    	cout<<c[i][j]<<" ";
		}
		cout<<endl;
	}    
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_41297324/article/details/84642103
今日推荐