Skip to content

Instantly share code, notes, and snippets.

@vshivam
Last active June 6, 2016 10:11
Show Gist options
  • Save vshivam/65cdbe30178e858b37a94aee4b4b3530 to your computer and use it in GitHub Desktop.
Save vshivam/65cdbe30178e858b37a94aee4b4b3530 to your computer and use it in GitHub Desktop.
Facebook Hacker Cup 2016 Round 1
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Main {
// https://gist.githubusercontent.com/maksverver/89776622d809e3f8e69e/raw/59d6819bf90f527f8e3597abda0a905dd4a2743a/A.txt
public static void main(String[] args) {
File input = new File("/home/shivam/Desktop/work/code/algo/src/input.txt");
try {
Scanner scanner = new Scanner(input);
int case_num = 0;
int t = Integer.parseInt(scanner.nextLine());
while (scanner.hasNextLine()) {
int len = Integer.parseInt(scanner.nextLine());
String[] nums = (scanner.nextLine()).split(" ");
int extra = 0;
int last = 0;
int index = 0;
while (index < len) {
for (int i = 0; i < 4; i++) {
if (i == 0) {
last = Integer.parseInt(nums[index]);
index++;
} else if ((index < len) && (last < Integer.parseInt(nums[index])) && (Integer.parseInt(nums[index]) <= (last + 10))) {
last = Integer.parseInt(nums[index]);
index++;
} else {
last = last + 10;
extra++;
}
}
}
System.out.println("Case #" + (++case_num) + ": " + extra);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment