View Code of Problem 10

#include <stdio.h>

void main()
{
	int n,i,j;
	scanf("%d",&n);
	int a[100];
	while(n--)
	{
		for(i=0;i<4;i++)
	   {
		  scanf("%d",&a[i]);
    	}
	    for(i=3;i>0;i--)
	   {
		  for(j=i-1;j>=0;j--)
		  {
			  if(a[i]==a[j])
			  {
				a[i]=2*a[i];
				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; 
			        j--;
				  }
			   }
		   }
	    }
	    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