My program needs to get two vectors, A and B. This defines the set
A pikachu B
as the set formed by the elements that appear in A or B. It also has the set
A chikorita B
As the set consisting of the elements that appear in both A and B .
But the outpout is going wrong. It would have to be for example:
input
3 4
4 6 2
3 5 7 9output
pikachu: {2,3,4,5,6,7,9}
chikorita: {}
ps: I did not finish the code, I only did the part where the two vectors are the same, but still it is not printing correctly, what can it be?
My code:
#include <stdio.h>
void levet(int x, long long int vetor[]){
int i;
for(i=0;i<x;i++)
{
scanf("%lld",&vetor[i]);
}
}
void arrumarvet(long long int vetor[], int n){
int i,j,aux;
for(i=0;i<n;i++){
for(j=0;j<n-1;j++){
if(vetor[j] > vetor[j+1]){
aux=vetor[j];
vetor[j]=vetor[j+1];
vetor[j+1]=aux;
}
}
}
}
int main(){
int i,j,n,m,cont=0;
long long int vetA[10000], vetB[10000];
long long int vetaux[10000];
scanf("%d %d",&n, &m);
levet(n,vetA);
levet(m,vetB);
arrumarvet(vetA,n);
arrumarvet(vetB,m);
for(i=0;i<n; i++){
for(j=0;j<m;j++){
if(vetA[j]== vetB[j]){
cont++;
}
else if(vetA[j] != vetB[j]){
vetaux[j]=vetA[j];
}
}
}
if(cont== m){
printf("pikachu: {");
for(i=0;i<m;i++)
{
printf("%d,",vetA[i]);
}
printf("}\n");
printf("chikorita: {");
for(i=0;i<m;i++)
{
printf("%d,",vetA[i]);
}
printf("}\n");
}
return 0;
}