View Code of Problem 10

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

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

		for(j=3;j>0;j--)
				if(a[j]==0)
				{
					
					for(k=j;k>0;k--)
						a[k]=a[k-1];
					a[0]=0;
					j=4;
					if(a[3]!=0)
						break;
				}
			}
		 
		for(j=0;j<3;j++)
			printf("%d ",a[j]);
		printf("%d\n",a[3]);
	}
	

	
	return 0;
}

Double click to view unformatted code.


Back to problem 10