Last active
December 15, 2015 16:39
-
-
Save adrientetar/5290804 to your computer and use it in GitHub Desktop.
Google Code Jam - Store Credit (Africa 2010)
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
| /** | |
| * Google Code Jam | |
| * Qualification Round Africa 2010 | |
| * | |
| * Copyright (C) 2013 Adrien Tétar, All Rights Reserved. | |
| */ | |
| import java.util.Scanner; | |
| class Main { | |
| public static void main(String[] args) { | |
| Scanner input = new Scanner(System.in); | |
| int N = input.nextInt(); // "Number of cases? " | |
| for (int a=1; a<=N; a++) { | |
| int C = input.nextInt(); // "#" + N + ": Credit? " | |
| int I = input.nextInt(); // "#" + N + ": How many items? " | |
| int[] L = new int[I]; | |
| for (int b=0; b<I; b++) { | |
| L[b] = input.nextInt(); | |
| } | |
| for (int b=0; b<I; b++) { | |
| int buf = C-L[b]; | |
| for (int c=b+1; c<I; c++) { | |
| if (buf == L[c]) | |
| System.out.println("Case #" + a + ": " + (b+1) + " " + (c+1)); | |
| } | |
| } | |
| } | |
| } | |
| } |
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
| /** | |
| * Google Code Jam | |
| * Qualification Round Africa 2010 (B) | |
| * | |
| * Copyright (C) 2013 Adrien Tétar, All Rights Reserved. | |
| */ | |
| import java.util.Scanner; | |
| class Main { | |
| public static void main(String[] args) { | |
| Scanner input = new Scanner(System.in); | |
| int N = input.nextInt(); // "Number of cases? " | |
| input.nextLine(); | |
| for (int a=1; a<=N; a++) { | |
| String line = input.nextLine(); | |
| String[] words = line.split(" "); // "w1 w2 w3 etc." | |
| String buf; | |
| for (int b=0; b<(words.length/2); b++) { | |
| buf = words[(words.length-1)-b]; | |
| words[(words.length-1)-b] = words[b]; | |
| words[b] = buf; | |
| } | |
| System.out.print("Case #" + a + ": "); | |
| for (int b=0; b<words.length; b++) { | |
| if (b != 0) | |
| System.out.print(" "); | |
| System.out.print(words[b]); | |
| } | |
| System.out.println(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment