Guest User

Untitled

a guest
Dec 16th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. const int MAX=3;
  5. typedef int tArrayEnt[MAX];
  6. typedef bool tArrayBool[MAX];
  7. void leerArray(tArrayEnt a, tArrayEnt b);
  8. void inicializarBool(tArrayBool usados);
  9. bool mismosElementos(const tArrayEnt a,const tArrayEnt b,tArrayBool usados);
  10. bool estaElemento(const tArrayEnt a,const tArrayEnt b, tArrayBool usados);
  11.  
  12.  
  13. int main()
  14. {
  15. tArrayEnt a,b;
  16. tArrayBool usados;
  17. leerArray(a,b);
  18. inicializarBool(usados);
  19. if(mismosElementos(a,b,usados))
  20. {
  21. cout << "Elementos repetidos";
  22. }
  23. else
  24. {
  25. cout << "Elementos no repetidos";
  26. }
  27. return 0;
  28. }
  29.  
  30. void leerArray(tArrayEnt a,tArrayEnt b)
  31. {
  32. cout << "Introduce los valores del primer array:";
  33. for(int i=0; i<MAX; i++)
  34. {
  35. cin >> a[i];
  36. }
  37.  
  38. cout << "Introduce los valores del segundo array:";
  39. for(int i=0; i<MAX; i++)
  40. {
  41. cin >> b[i];
  42. }
  43. }
  44.  
  45. void inicializarBool(tArrayBool usados)
  46. {
  47. for(int i=0; i<MAX; i++)
  48. {
  49. usados[i]=false;
  50. }
  51. }
  52.  
  53. bool mismosElementos(const tArrayEnt a,const tArrayEnt b,tArrayBool usados)
  54. {
  55. int i=0;
  56. while(i<MAX && estaElemento(a[i],b,usados))
  57. {
  58. i++;
  59. }
  60. return i==MAX;
  61. }
  62.  
  63. bool estaElemento(const tArrayEnt a,const tArrayEnt b, tArrayBool usados)
  64. {
  65. int i=0;
  66. bool encontrado;
  67. int elemento=a[i];
  68. while(i<MAX &&(elemento!=b[i] || usados[i]))
  69. {
  70. i++;
  71. }
  72. encontrado=i<MAX;
  73. if(encontrado)
  74. {
  75. usados[i]=true;
  76. }
  77. return encontrado;
  78. }
Add Comment
Please, Sign In to add comment