Instantly share code, notes, and snippets.

Embed
What would you like to do?
GCJ 2014 - Magic Trick Problem
package com.bchetty.gcj2014;
import java.util.ArrayList;
import java.util.List;
/**
* GCJ 2014 - Magic Trick Problem
*
* @author Babji, Chetty
*/
public class MagicTrick {
/**
*
* @param firstRow
* @param rowList1
* @param secondRow
* @param rowList2
* @return
*/
public String findTrickResult(List<Integer> rowList1, List<Integer> rowList2) {
int count = 0;
int res = 0;
String result = null;
for(int i=0;i<rowList1.size();i++) {
int temp = rowList1.get(i);
if(rowList2.contains(temp)) {
count++;
res = temp;
}
}
switch(count) {
case 0:
result = "Volunteer cheated!";
break;
case 1:
result = "" + res;
break;
default:
result = "Bad magician!";
break;
}
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment