Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int LeerSecuencia(int vec[], int l) {
  6.  
  7. for (int i = 0; i < l; i++) {
  8. cout << "Elemento " << i;
  9. cin >> vec[i];
  10. cout << endl;
  11. }
  12.  
  13. cout << "TErminAdo\n" << endl;
  14. }
  15.  
  16. bool Contenida(int v1[], int l1, int v2[], int l2) {
  17.  
  18. int i = 0;
  19. int j = 0;
  20.  
  21. if (l1 > l2) {
  22. while (i < l2) {
  23. if (v1[i] == v2[j]) {
  24. j = 0; i++;
  25. }
  26.  
  27. else if (j < l1) {
  28. j++;
  29. }
  30.  
  31. else {
  32. i = l2 + 1;
  33. }
  34. }
  35.  
  36. return i == l1;
  37. }
  38.  
  39. else {
  40. while (i < l1) {
  41. if (v1[i] == v2[j]) {
  42. j = 0; i++;
  43. }
  44.  
  45. else if (j < l2) {
  46. j++;
  47. }
  48.  
  49. else {
  50. i = l2 + 1;
  51. }
  52. }
  53.  
  54. return i == l2;
  55. }
  56. }
  57.  
  58. int main() {
  59. const int l1 = 4; int vec1[l1];
  60. const int l2 = 3; int vec2[l2];
  61.  
  62. LeerSecuencia(vec1, l1);
  63. LeerSecuencia(vec2, l2);
  64.  
  65. if (Contenida(vec1, l1, vec2, l2)) {
  66. cout << "jaja si.";
  67. }
  68. else {
  69. cout << "jaja no.";
  70. }
  71.  
  72. return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement