-
-
Save eduardojunio/feaa0e0237c0a43651b891da54038aee to your computer and use it in GitHub Desktop.
85 - Adivinhe The Huxley
This file contains hidden or 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
#include <stdio.h> | |
void lerSenha(int tamanho, int senha[]); | |
void tentarChutes(int tamanho, int senha[]); | |
int main() { | |
int k, n, i; | |
scanf("%d", &k); | |
for (i = 0; i < k; i++) { | |
scanf("%d", &n); | |
int senha[n+1]; | |
lerSenha(n, senha); | |
tentarChutes(n, senha); | |
} | |
return 0; | |
} | |
void lerSenha(int tamanho, int senha[]) { | |
int i; | |
for (i = 0; i < tamanho; i++) { | |
scanf("%1d", &senha[i]); | |
} | |
} | |
int excelente(int numero, int posicao, int array[]) { | |
if (numero == array[posicao]) { | |
return 1; | |
} | |
return 0; | |
} | |
int bom(int numero, int tamanho, int array[]) { | |
int i; | |
for (i = 0; i < tamanho; i++) { | |
if (numero == array[i]) { | |
return 1; | |
} | |
} | |
return 0; | |
} | |
int seRepeteNaArray(int numero, int posicao, int tamanho, int array[]) { | |
int i; | |
for (i = (posicao + 1); i < tamanho; i++) { | |
if (array[i] == numero) { | |
return 1; | |
} | |
} | |
return 0; | |
} | |
void tentarChutes(int tamanho, int senha[]) { | |
int chute[tamanho], e = 0, b = 0; | |
while (e != tamanho) { | |
lerSenha(tamanho, chute); | |
e = 0, b = 0; | |
int i, j = 0; | |
for (i = 0; i < tamanho; i++) { | |
j += chute[i]; | |
} | |
if (j == 0) { | |
break; | |
} | |
for (i = 0; i < tamanho; i++) { | |
if (excelente(chute[i], i, senha)) { | |
e++; | |
} else if (bom(chute[i], tamanho, senha) | |
&& !seRepeteNaArray(chute[i], i, tamanho, chute)) { | |
b++; | |
} | |
} | |
printf("(%d,%d)\n", e, b); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment