Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- const int MAX=3;
- typedef int tArrayEnt[MAX];
- typedef bool tArrayBool[MAX];
- void leerArray(tArrayEnt a, tArrayEnt b);
- void inicializarBool(tArrayBool usados);
- bool mismosElementos(const tArrayEnt a,const tArrayEnt b,tArrayBool usados);
- bool estaElemento(const tArrayEnt a,const tArrayEnt b, tArrayBool usados);
- int main()
- {
- tArrayEnt a,b;
- tArrayBool usados;
- leerArray(a,b);
- inicializarBool(usados);
- if(mismosElementos(a,b,usados))
- {
- cout << "Elementos repetidos";
- }
- else
- {
- cout << "Elementos no repetidos";
- }
- return 0;
- }
- void leerArray(tArrayEnt a,tArrayEnt b)
- {
- cout << "Introduce los valores del primer array:";
- for(int i=0; i<MAX; i++)
- {
- cin >> a[i];
- }
- cout << "Introduce los valores del segundo array:";
- for(int i=0; i<MAX; i++)
- {
- cin >> b[i];
- }
- }
- void inicializarBool(tArrayBool usados)
- {
- for(int i=0; i<MAX; i++)
- {
- usados[i]=false;
- }
- }
- bool mismosElementos(const tArrayEnt a,const tArrayEnt b,tArrayBool usados)
- {
- int i=0;
- while(i<MAX && estaElemento(a[i],b,usados))
- {
- i++;
- }
- return i==MAX;
- }
- bool estaElemento(const tArrayEnt a,const tArrayEnt b, tArrayBool usados)
- {
- int i=0;
- bool encontrado;
- int elemento=a[i];
- while(i<MAX &&(elemento!=b[i] || usados[i]))
- {
- i++;
- }
- encontrado=i<MAX;
- if(encontrado)
- {
- usados[i]=true;
- }
- return encontrado;
- }
Add Comment
Please, Sign In to add comment