Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2015
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. ifstream IN("input");
  9. ofstream OUT("output");
  10. if(IN&&OUT)
  11. {
  12. int X[400], P[20], n_el, dimP;
  13.  
  14. for(int i=0;i<400;i++)
  15. {
  16. X[i]=0;
  17. }
  18. for(int i=0;i<20;i++)
  19. {
  20. P[i]=20;
  21. }
  22.  
  23. IN>>n_el;
  24.  
  25. for(int i=0;i<n_el;i++)
  26. {
  27. IN>>X[i];
  28. }
  29.  
  30. IN>>dimP;
  31.  
  32. for(int i=0;i<dimP;i++)
  33. {
  34. IN>>P[i];
  35. }
  36.  
  37. match(X, n_el, P, dimP, i, count_match, OUT);
  38. OUT>>"fine"<<endl;
  39. IN.close();
  40. OUT.close();
  41. }
  42. else
  43. OUT<<"errore con i files"<<endl;
  44. }
  45.  
  46. void match(int *X,int *P,int dimX,int dimP, int i, int count_match, ofstream&OUT)
  47. {
  48.  
  49. if(dimX<dimP-1)
  50. {
  51. return;
  52. }
  53.  
  54. else
  55. //condizione che mi blocca la ricorsione
  56. {
  57. int count_match=0;
  58. if(trovato(int X,int P, int dimP,int i))
  59. {
  60. count_match++;
  61.  
  62.  
  63. OUT<<"Match n "<<count_match<<"a partire dalla posizione "<<i<<endl;
  64.  
  65. }
  66.  
  67. match(int X+1,int P,int dimP, int i+1, int count_match,ofstream&OUT)
  68.  
  69. }
  70. }
  71.  
  72. bool trovato(int *X,int*P,int dimP,int indice)
  73. {
  74.  
  75. int indice=0;
  76. bool trovato=true;
  77.  
  78. if(dimP==0)
  79. {
  80. return trovato;
  81. }
  82.  
  83. else //caso che devo discutere
  84. {
  85.  
  86. if(X[indice]!=P[indice])
  87. {
  88.  
  89. trovato=false;
  90. return trovato;
  91. }
  92. else
  93. {
  94.  
  95. trovato(int X,int P,int dimP,int indice+1);
  96. }
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement