0
I decided that 2018 would learn to program, and I’m studying on my own, and by researching I found this judge named Uri, I’m having a hard time finding the error that is in my code, I did all the tests, and when I submit the question of only 10% error someone could help me.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void)
{
int i, j, vetor[100], c = 0, teste, k;
char nome[100];
char primeiro[6] = {'a', 'k', 'u', 'G', 'Q'}, segundo[6] = {'b', 'l', 'v',
'I', 'S'};
char terceiro[7] = {'E', 'O', 'Y', 'c', 'm', 'w'}, quarto[7] = {'F', 'P', 'Z', 'd', 'n', 'x'};
char quinto[6] = {'J', 'T', 'e', 'o', 'y'}, sexto[7] = {'D', 'N', 'X', 'f', 'p', 'z'};
char setimo[6] = {'A', 'K', 'U', 'g', 'q'}, oitavo[6] = {'C', 'M', 'W', 'h', 'r'};
char nono[6] = {'B', 'L', 'V', 'i', 's'}, deimo[5] = {'H', 'R', 'j', 't'};
scanf("%d", &teste);
for(k = 0; k < teste; k++)
{
setbuf(stdin, NULL);
fgets(nome, 40, stdin);
int tam = strlen(nome);
for(i = 0, c = 0; i < tam; i++)
{
for(j = 0; j < strlen(primeiro); j++)
{
if(nome[i] == primeiro[j])
{
vetor[c++] = 0;
break;
}
}
for(j = 0; j < strlen(segundo); j++)
{
if(nome[i] == segundo[j])
{
vetor[c++] = 1;
break;
}
}
for(j = 0; j < strlen(terceiro); j++)
{
if(nome[i] == terceiro[j])
{
vetor[c++] = 2;
break;
}
}
for(j = 0; j < strlen(quarto); j++)
{
if(nome[i] == quarto[j])
{
vetor[c++] = 3;
break;
}
}
for(j = 0; j < strlen(quinto); j++)
{
if(nome[i] == quinto[j])
{
vetor[c++] = 4;
break;
}
}
for(j = 0; j < strlen(sexto); j++)
{
if(nome[i] == sexto[j])
{
vetor[c++] = 5;
break;
}
}
for(j = 0; j < strlen(setimo); j++)
{
if(nome[i] == setimo[j])
{
vetor[c++] = 6;
break;
}
}
for(j = 0; j < strlen(oitavo); j++)
{
if(nome[i] == oitavo[j])
{
vetor[c++] = 7;
break;
}
}
for(j = 0; j < strlen(nono); j++)
{
if(nome[i] == nono[j])
{
vetor[c++] = 8;
break;
}
}
for(j = 0; j < strlen(deimo); j++)
{
if(nome[i] == deimo[j])
{
vetor[c++] = 9;
break;
}
}
}
if(c <= 11)
{
for(i = 0; i < c; i++)
{
printf("%d", vetor[i]);
}
printf("\n");
}
else
{
for(i = 0; i < 12; i++)
{
printf("%d", vetor[i]);
}
printf("\n");
}
memset(vetor, 0, sizeof(vetor));
}
system("pause");
return 0;
}
Did any of the answers solve your question? Do you think you can accept one of them? Check out the [tour] how to do this, if you haven’t already. You would help the community by identifying what was the best solution for you. You can accept only one of them. But you can vote on any question or answer you find useful on the entire site (when you have enough score).
– Maniero