import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); for (int k = in.nextInt(); k > 0; k--) { int d = 0; int x; int a[] = new int[4]; for (int i = 0; i < 4; i++) { a[i] = in.nextInt(); } for (int j = 0; j < 4; j++) { for (int i = 1; i < 4; i++) { if (a[i] == 0) { x = a[i]; a[i] = a[i - 1]; a[i - 1] = x; } } } for (int i = 3; i > 0; i--) { if (a[i] == a[i - 1]) { a[i] *= 2; d++; a[i - 1] = 0; } } for (int j = 0; j < 4; j++) { for (int i = 1; i < 4; i++) { if (a[i] == 0) { x = a[i]; a[i] = a[i - 1]; a[i - 1] = x; } } } for (int i = 0; i < 3; i++) { System.out.print(a[i] + " "); } System.out.println(a[3]); } } } |
Double click to view unformatted code.