View Code of Problem 10

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

Double click to view unformatted code.


Back to problem 10