// Google Code Jam 2014 Qualification Round A Magic Trick
// Problems: https://code.google.com/codejam/contest/2974486/dashboard#s=p0
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
//Google Code Jam
public class GoogleCode1 {
 private static MyScanner in;
 private static PrintStream out = System.out;
 private static PrintStream sysout = System.out;
 static int caseNum;
 private static void solve() throws IOException
 {
  PreCompute();
  int C = in.nextInt();
  for (int i = 0; i < C; i++) {
   caseNum = i + 1;
   out.print("Case #" + caseNum + ": ");
   solveCase();
  }
 }
 private static void PreCompute() {
 }
 private static void solveCase() throws IOException {
  int g1 = in.nextInt();
  int[] r1 = new int[4];
  for (int i = 0; i < 4; i++) {
   for (int j = 0; j < 4; j++) {
    if (i + 1 == g1)
     r1[j] = in.nextInt();
    else
     in.nextInt();
   }
  }
  int g2 = in.nextInt();
  int[] r2 = new int[4];
  for (int i = 0; i < 4; i++) {
   for (int j = 0; j < 4; j++) {
    if (i + 1 == g2)
     r2[j] = in.nextInt();
    else
     in.nextInt();
   }
  }
  int match = 0;
  int num = 0;
  for (int i = 0; i < 4; i++) {
   int x = r1[i];
   for (int j = 0; j < 4; j++) {
    if (x == r2[j]) {
     num = x;
     match++;
    }
   }
  }
  if (match == 1)
   out.println(num);
  else if (match == 0)
   out.println("Volunteer cheated!");
  else
   out.println("Bad magician!");
 }
 public static void main(String[] args) throws IOException {
  // helpers for input/output
  boolean usingFileForIO = true;
  if (usingFileForIO) {
   // using input.txt and output.txt as I/O
   in = new MyScanner("E:\\zin.txt");
   out = new PrintStream("E:\\zout.txt");
  }
  else {
   in = new MyScanner();
   out = System.out;
  }
  solve();
 }
 // =====================================
 static class MyScanner {
  Scanner inp = null;
  public MyScanner() throws IOException
  {
   inp = new Scanner(System.in);
  }
  public MyScanner(String inputFile) throws IOException {
   inp = new Scanner(new FileInputStream(inputFile));
  }
  public int nextInt() throws IOException {
   return inp.nextInt();
  }
  public long nextLong() throws IOException {
   return inp.nextLong();
  }
  public double nextDouble() throws IOException {
   return inp.nextDouble();
  }
  public String nextString() throws IOException {
   return inp.next();
  }
  public String nextLine() throws IOException {
   return inp.nextLine();
  }
 }
}
No comments:
Post a Comment