Skip to content

Instantly share code, notes, and snippets.

@pinglunliao
Last active November 5, 2019 08:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pinglunliao/dc90edcfb97023153573 to your computer and use it in GitHub Desktop.
Save pinglunliao/dc90edcfb97023153573 to your computer and use it in GitHub Desktop.
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
int CNT = 4;
int answer[CNT];
int guess[CNT];
int idx = 0;
int round = 0;
while( scanf("%d %d %d %d", &answer[0], &answer[1], &answer[2], &answer[3])!=EOF ) {
scanf("%d", &round);
int a[round] = { 0 };
int b[round] = { 0 };
idx = 0;
while( idx < round ) {
int guessIdx = 0;
int found[CNT] = { 0 };
while( guessIdx < CNT ) {
scanf("%d", &guess[guessIdx]);
// How many A.
if(guess[guessIdx] == answer[guessIdx]) {
a[idx]++;
found[guessIdx] = 1;
} else {
found[guessIdx] = 0;
}
guessIdx++;
}
// How Many B.
for( guessIdx = 0; guessIdx < CNT; guessIdx++) {
if( found[guessIdx] != 1 )
for(int answerIdx = 0; answerIdx < CNT; answerIdx++) {
if( found[answerIdx] == 0 && (guess[guessIdx] == answer[answerIdx]) && guessIdx != answerIdx ) {
b[idx]++;
found[answerIdx] = 2;
break;
}
}
}
idx++;
}
idx = 0;
while( idx < round ) {
printf("%dA%dB\n", a[idx], b[idx]);
idx++;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment