View Code of Problem 10

#include<stdio.h>
int main(){
	int n;
	int a[4];
	scanf("%d",&n);
	while(n--){
	
		int b[4]={0};
		for(int i=0;i<4;i++){
			scanf("%d",&a[i]);
		}
		for(int j=0;j<=3;j++){
			for(int i=3;i>0;i--){ //能互换的条件 
				if(a[i]==a[i-1]&&a[i]!=0&&b[i]==0&&b[i-1]==0){
					a[i]=2*a[i];
					a[i-1]=0;
					b[i]=1;
				}else if(a[i]==0&&i!=0){
					a[i]=a[i-1];
					a[i-1]=0;
				} 
				if(a[i]==0&&i==0){
					break;
				}
			}
		}
		for(int i=0;i<3;i++){
			printf("%d ",a[i]);
		}
		printf("%d\n",a[3]);	
		
	}
	
	return 0;
} 

Double click to view unformatted code.


Back to problem 10