import java.util.ArrayList; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); ArrayList<Integer> list = new ArrayList<>(); int[] c = new int[4]; for (int i = 0; i < n; i++) { for (int l = 0; l < 4; l++) { c[l] = scanner.nextInt(); } for (int j = 3; j > 0; j--) { boolean flag=false; while(true){ for(int k=3;k>0;k--){ if(c[k]==0&&c[k-1]!=0){ c[k]=c[k-1]; c[k-1]=0; flag=true; } else { flag=false; } } if(flag==false){ break; } } if (c[j] == c[j - 1] || c[j] == 0) { c[j] += c[j - 1]; c[j - 1] = 0; } } for(int o=0;o<4;o++){ if(o==0) { System.out.print(c[o]); } else { System.out.print(" "+c[o]); } } System.out.println(); } } } |
Double click to view unformatted code.