View Code of Problem 10

#include <stdio.h>
int main()
{
	int i,j,t;
	int n;
	int a[4];
    scanf("%d",&n);
   while(n--)
	{
		int k[4]={0};
		for(j=0;j<4;j++)
			scanf("%d",&a[j]);
	
		for(j=3;j>=0;j--)
			{
				if(a[j]!=0&&a[j]==a[j-1]&&k[j]==0&&k[j-1]==0)					//2222->2204->2024->0224->0044
				{
					a[j]=a[j]*2;
					a[j-1]=0;
					k[j]=1;						//标记
				}
				if(a[j]==0&&j!=0)
				{
					a[j]=a[j-1];
					a[j-1]=0;
				}
				if(a[j]==0&&j==0)
					break;
			}

		
 
		for(j=0;j<4;j++)
		{
			if(j+1==4)
				printf("%d",a[j]);
			else
				printf("%d ",a[j]);
		}
		printf("\n");
	}
}

Double click to view unformatted code.


Back to problem 10