View Code of Problem 10

#include<stdio.h>
#include<string.h>
int a[1000];
int main(){
	int i,j,t,k;

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

Double click to view unformatted code.


Back to problem 10