Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save autekroy/10574666 to your computer and use it in GitHub Desktop.
Save autekroy/10574666 to your computer and use it in GitHub Desktop.
Google Code Jam Qualification Round 2014 - Problem A. Magic Trick
//Google Code Jam Qualification Round 2014 - Problem A. Magic Trick
//https://code.google.com/codejam
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
freopen ("a_output.txt","w",stdout);
int square[4][4];
bool card[17];
int T, ans, tmp, findNum, finalAns;
scanf("%d", &T);
for(int testCase = 1; testCase <= T; testCase++)
{
memset(card, false, sizeof(card));
scanf("%d", &ans);
for(int i = 0; i < 4; i++)
for(int j = 0; j < 4; j++)
scanf("%d", &square[i][j]);
for(int i = 0; i < 4; i++)
card[ square[ans - 1][i] ] = true;
scanf("%d", &ans);
for(int i = 0; i < 4; i++)
for(int j = 0; j < 4; j++)
scanf("%d", &square[i][j]);
findNum = 0;
for(int i = 0; i < 4; i++)
if(card[ square[ans - 1][i] ] == true)
{
findNum++;
finalAns = square[ans - 1][i];
}
printf("Case #%d: ", testCase);
if(findNum == 1)
printf("%d\n", finalAns);
else if(findNum > 1)
printf("Bad magician!\n");
else if(findNum == 0)
printf("Volunteer cheated!\n");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment