View Code of Problem 10

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

Double click to view unformatted code.


Back to problem 10