TOPIC
Wrong Answer
Carinhaquemoralogoali asked 5 years ago
Alguém pode me ajudar a encontrar casos de teste nos quais meu código não funcione?
//It fills a deck with unrepeated elements and returns the number of distinct elements
int readDeck(int deck[], int lenght)
{
int aux, k = 0, i;
for (i = 0; i < lenght; i++)
{
scanf("%d", &aux);
if (k == 0)
{
deck[0] = aux;
k++;
}
else if (deck[k - 1] != aux)
{
deck[k] = aux;
k++;
}
}
return k;
}
//It calculates the size of the intersection between two vectors
int sizeIntersection(int deckA[], int deckB[], int elementsA, int elementsB)
{
int i, k, sair, numIntersections = 0;
for (i = 0; i < elementsA; i++)
{
sair = 1;
while (sair && k < elementsB)
{
if (deckA[i] == deckB[k])
{
numIntersections = numIntersections + 1;
sair = 0;
}
else if (deckA[i] > deckB[k])
k++;
else
sair = 0;
}
}
return numIntersections;
}
int main()
{
int numberOfCardsA, numberOfCardsB;
int distinctElementsA, distinctElementsB, intersection;
int deckA[100000], deckB[100000];
int aux, i;
scanf("%d %d", &numberOfCardsA, &numberOfCardsB);
while (numberOfCardsA != 0 && numberOfCardsB != 0)
{
distinctElementsA = readDeck(deckA, numberOfCardsA);
distinctElementsB = readDeck(deckB, numberOfCardsB);
intersection = sizeIntersection(deckA, deckB, distinctElementsA, distinctElementsB);
//The number of possible card exchanges is equal to the number of cards of the
// smaller deck minus the magnitude of the intersection between the two decks.
if (distinctElementsA >= distinctElementsB)
{
if (distinctElementsB - intersection >= 0)
printf("%d\n", distinctElementsB - intersection);
else
printf("0\n");
}
else
{
if (distinctElementsA - intersection >= 0)
printf("%d\n", distinctElementsA - intersection);
else
printf("0\n");
}
scanf("%d %d", &numberOfCardsA, &numberOfCardsB);
}
return 0;
}
This topic has not been answered yet. Be the first!