View Code of Problem 10

#include <stdio.h>
#include <string.h>
#include <math.h>

int main(){
	int t,i,j;
	scanf("%d",&t);
	int a[100];
	while(t--){
		for(i=0;i<=3;i++){
			scanf("%d",&a[i]);
		}
		for(i=3;i>=0;i--){
			for(j=i-1;i>=0;j--){
				if(a[i]==a[j]){
					a[i]=a[i]*2;
					a[j]=0;
				}	
			}	
		}
		
		for(i=3;i>=0;i--){
			if(a[i]==0){
				for(j=i-1;j>0;j--){
					if(a[j]>0){
						a[i]=a[j];
						a[j]=0;
						i--;
					}
				}
			}
		}
		for(i=0;i<4;i++)
		{
			if(i==3)
			   printf("%d\n",a[i]);
			else
			   printf("%d ",a[i]);
		}
		
	}
	

}

Double click to view unformatted code.


Back to problem 10