Advertisement
Guest User

Untitled

a guest
May 25th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #include<iostream>
  2.  
  3. using namespace std;
  4.  
  5. bool controllo(int *X, int *P, int dimP)
  6. {
  7. if(dimP==0)
  8. {
  9. return true;
  10. }
  11. else
  12. {
  13. if(X[0]!=P[0])
  14. {
  15. return false;
  16. }
  17. else
  18. {
  19. controllo(X+1,P+1,dimP-1);
  20. }
  21. }
  22. }
  23.  
  24.  
  25.  
  26. int match(int *X, int *P, int dim, int dimP, int i, int count_match)
  27. {
  28. if(i<dim)
  29. {
  30.  
  31. if(controllo(X,P,dimP)==true)
  32. {
  33. count_match++;
  34. cout<<"match n."<<count_match<<" a partire dalla posizione "<<i<<endl;
  35.  
  36. }
  37. match(X+1,P,dim,dimP,i+1,count_match);
  38.  
  39. }
  40. return count_match;
  41. }
  42.  
  43.  
  44.  
  45.  
  46. main()
  47. {
  48.  
  49. int X[400], n_el, P[20], dimP;
  50. cin>>n_el;
  51. for(int i=0; i<n_el;i++)
  52. cin>>X[i];
  53. cin>>dimP;
  54. for(int i=0; i<dimP;i++)
  55. cin>>P[i];
  56. int a= match(X,P,n_el,dimP,0,0);
  57. cout<<"n. di match trovati= "<< a <<endl;
  58. cout<<"end"<<endl;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement