
GCJ-Qualification 2014-A. Magic Trick .
It's a for everybody to learn and discuss.
If there is any mistake or comment, please let me know. :D
此乃GCJ-Qualification 2014-A. Magic Trick 的AC code!
歡迎一同討論學習,如有錯誤與任何建議請留言 : )
前往 Google Code Jam!
Please feel free to use it after adding this blog as an reference. (http://autekroy.blogspot.tw) If there is any mistake or comment, please let me know. :D
歡迎使用與分享任何內容,但請記得標示此部落格為出處。(http://autekroy.blogspot.tw/) 如果有發現任何的錯誤與建議請留言或跟我連絡。 : )
前往 Google Code Jam!
This file contains 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 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; | |
} |
歡迎使用與分享任何內容,但請記得標示此部落格為出處。(http://autekroy.blogspot.tw/) 如果有發現任何的錯誤與建議請留言或跟我連絡。 : )
沒有留言:
張貼留言
請留下您的任何想法或建議!
Please leave any thought or comment!