View Code of Problem 10

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

    scanf("%d",&t);

    while(t--)
    {
        for(i = 0;i < 4;i++)
            scanf("%d",&a[i]);

        int b[4] = {0};

        for(j = 0;j < 4;j++)
        {
            for(i=3;i>0;i--)
		    {
                if(a[i]==a[i-1] && a[i]!=0 && b[i] == 0 && b[i-1] == 0)
                {
                    a[i]=2*a[i];
                    a[i-1]=0;
                    b[i] = 1;
                }
                else if(a[i]==0)
                {
					a[i]=a[i-1];
				    a[i-1]=0;
                }
		    }
        }

        for(i=0;i<3;i++)
            printf("%d ",a[i]);

        printf("%d\n",a[3]);

    }

    return 0;
}


Double click to view unformatted code.


Back to problem 10