View Code of Problem 10

#include <iostream>
#include <cstdio>

using namespace std;
void fun(int b[],int t){
	for(int j=0;j<t;j++){
		for(int i=0;i<t;i++){
			if(b[i]!=0&&b[i+1]==0){
				b[i+1]=b[i];
				b[i]=0;
			} 
		}
	}
} 
int main(){
	int n;cin>>n;
	while(n--){
		int a[4]={0};
		scanf("%d %d %d %d",&a[0],&a[1],&a[2],&a[3]);
		for(int j=3;j>=0;j--){
			for(int k=j-1;k>=0;k--){
				if(a[j]==a[k]){
					a[j]=2*a[j];
					a[k]=0;
				}
			}
		}
		fun(a,4);
		cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<" "<<a[3]<<endl; 
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 10