Created
April 26, 2011 16:31
-
-
Save stphung/942609 to your computer and use it in GitHub Desktop.
TopCoder SRM 504 Division 2 - 250 point problem
This file contains hidden or 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
| import java.util.Arrays; | |
| public class ComparerInator { | |
| public int makeProgram(int[] A, int[] B, int[] wanted) { | |
| if (same(A, wanted)) | |
| return 1; | |
| else if (same(B, wanted)) | |
| return 1; | |
| else if (ltTest1(A, B, wanted)) | |
| return 7; | |
| else if (ltTest2(A, B, wanted)) | |
| return 7; | |
| else | |
| return -1; | |
| } | |
| private boolean same(int[] in, int[] wanted) { | |
| return Arrays.equals(in, wanted); | |
| } | |
| private boolean ltTest1(int[] first, int[] second, int[] wanted) { | |
| for (int i = 0; i < first.length; i++) { | |
| if (first[i] < second[i]) { | |
| if (wanted[i] != first[i]) | |
| return false; | |
| } else { | |
| if (wanted[i] != second[i]) | |
| return false; | |
| } | |
| } | |
| return true; | |
| } | |
| private boolean ltTest2(int[] first, int[] second, int[] wanted) { | |
| for (int i = 0; i < first.length; i++) { | |
| if (first[i] < second[i]) { | |
| if (wanted[i] != second[i]) | |
| return false; | |
| } else { | |
| if (wanted[i] != first[i]) | |
| return false; | |
| } | |
| } | |
| return true; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment