Last active
August 29, 2015 14:20
-
-
Save chinying/e1b99a6a033455a8457a to your computer and use it in GitHub Desktop.
so i had this question for my finals today : take 3 integers from the command line and print them in descending order. i did it without sorting :)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class f{ | |
public static int max(int x, int y){ | |
return (x > y) ? x : y; | |
} | |
public static int min(int x, int y){ | |
return (x < y) ? x : y; | |
} | |
public static void main(String [] args){ | |
int i, hi, mid, lo, x1 = 0, x2 = 0; | |
if (args.length != 3) return; | |
int arr[] = new int[3]; | |
for (i=0; i<3; i++) arr[i] = Integer.parseInt(args[i]); | |
hi = max(max(arr[0], arr[1]), arr[2]); | |
lo = min(min(arr[0], arr[1]), arr[2]); | |
for (i=0; i<3; i++) x1^=arr[i]; | |
x2^=hi; | |
x2^=lo; | |
mid = x1^x2; | |
System.out.printf("%d %d %d\n", hi, mid, lo); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment