View Code of Problem 10

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

Double click to view unformatted code.


Back to problem 10