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=3;j>0;j++){
   	 if(b[j]==0&&b[j-1]>0){
    	 b[j]=b[j-1];
   	    b[j-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=3;j>0;j++){
  	  if(b[j]==0&&b[j-1]>0){
  	   b[j]=b[j-1];
  	     b[j-1]=0;
  	 	 }
 		 }
 		 for(int j=0;j<4;j++){
 		 printf("%d ",b[j]);
 		 }
	}
}

Double click to view unformatted code.


Back to problem 10