View Code of Problem 10

import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T=sc.nextInt();

for(int j=0;j<T;j++){
int a[]=new int[4];
for(int i=0;i<4;i++){
a[i]=sc.nextInt();
}
for(int i=3;i>=1;i--){
	if(a[i]==0){
		a[i]=a[i-1];
		a[i-1]=0;
	}
}

	if(a[3]==a[2]&&a[3]!=0){
    a[3]=a[3]*2;
    a[2]=a[1];  
    a[1]=a[0];
    a[0]=0; 
}

	if(a[2]==a[1]&&a[2]!=0){
    a[2]=a[2]*2;
    a[1]=a[0];  
    a[0]=0; 
}
	if(a[1]==a[0]&&a[1]!=0){
    a[1]=a[0]*2;
    a[0]=0;   
}



for(int i=0;i<a.length;i++){
	if(i!=3)
	System.out.print(a[i]+" ");
	else
	System.out.print(a[i]);
}
}
}
}

Double click to view unformatted code.


Back to problem 10