Last active
October 6, 2015 16:03
-
-
Save rodrigomb81/9e3896604e33e8c62d87 to your computer and use it in GitHub Desktop.
This file contains 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> | |
#define MAX 10 | |
void intersectarUnicos(int A[MAX], int B[MAX], int R[MAX]); | |
int main () { | |
int a[MAX] = {1, 2, 3, 2, 4, 5, 8, 0, 9, 15}; | |
int b[MAX] = {3, 4, 7, 12, 2, 1, 4, 8}; | |
int r[MAX] = {0}; /*espero que sea [1, 3, 8, 0, ..., 0]*/ | |
intersectarUnicos(a, b, r); | |
int i = 0; | |
putchar('\n'); | |
for(i = 0; i < MAX; i++) { | |
printf(" %d ", r[i]); | |
} | |
putchar('\n'); | |
return 0; | |
} | |
int repeticiones(int elemento, int vector[MAX]) { | |
int resultado = 0; | |
int i = 0; | |
for (i = 0; i < MAX; i++) { | |
if (elemento == vector[i]) { | |
resultado++; | |
} | |
} | |
return resultado; | |
} | |
void intersectarUnicos(int A[MAX], int B[MAX], int R[MAX]) { | |
int i, indiceActual = 0; | |
for (i = 0; i < MAX; i++) { | |
int es_unico_en_A = repeticiones(A[i], A) == 1; | |
int es_unico_en_B = repeticiones(A[i], B) == 1; | |
if (es_unico_en_A && es_unico_en_B) { | |
R[indiceActual] = A[i]; | |
++indiceActual; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment