View Code of Problem 10

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

Double click to view unformatted code.


Back to problem 10