View Code of Problem 10

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

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main() {
	int n,a[10]={0},i,j;
	scanf("%d",&n);
	while(n--)
	{
		scanf("%d %d %d %d",&a[0],&a[1],&a[2],&a[3]);
		for(i=3;i>=0;i--)
		{
			for(j=3;j>=0;j--)
			{
				if(a[j]==0)
				{
					a[j]=a[j-1];
					a[j-1]=0;
				}
			}
		}
		for(i=3;i>=0;i--)
		{
			if(a[i]!=0&&a[i]==a[i-1])
			{
				a[i]=a[i]*2;
				a[i-1]=0;
			}
		}
		for(i=3;i>=0;i--)
		{
			for(j=3;j>=0;j--)
			{
				if(a[j]==0)
				{
					a[j]=a[j-1];
					a[j-1]=0;
				}
			}
		}
		
		printf("%d %d %d %d\n",a[0],a[1],a[2],a[3]);
		
		
	}
	
	
		
	return 0;
}

Double click to view unformatted code.


Back to problem 10