NeroReflex

Esercizio_1_6_4_2016

May 10th, 2016
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1. #include<iostream>
  2. #include <string.h>
  3. using namespace std;
  4.  
  5. bool fetta_vuota(int f, int n_el);
  6. void match_fetta(int* X, int lim1, int lim2, int lim3, int n_el, int f, int*P, int dimP);
  7.  
  8. main()
  9. {
  10.    
  11.    int X[400]={},P[50], n_el, dimP, lim1,lim2,lim3;
  12.    memset((void*)&X[0], 0, sizeof(X));
  13.    
  14.    cin>>lim1>>lim2>>lim3;
  15.    cin>>n_el;
  16.    for(int i=0; i<n_el; i++)
  17.      cin >> X[i];
  18.    cin>>dimP;
  19.    for(int i=0; i<dimP; i++)
  20.    cin>>P[i];
  21.    
  22.    
  23.    for(int f=0; f<lim3 && !fetta_vuota(f,n_el); f++)
  24.        
  25.      match_fetta(X, lim1,lim2,lim3,n_el,f, P, dimP);
  26.      
  27.     cout<<"end"<<endl;    
  28. }
  29.  
  30. bool fetta_vuota(int f, int n_el)
  31. {
  32.     return (f >= n_el);
  33. }
  34.  
  35. void match_fetta(int* X, int lim1, int lim2, int lim3, int n_el, int f, int*P, int dimP) {
  36.     int match = 0;
  37.     int indice_att = 0;
  38.    
  39.     for (int a = 0; a < lim1; a++)
  40.     for (int b = 0; b < lim2; b++)
  41.     {
  42.         if (indice_att == (dimP )) {
  43.             match++;
  44.             indice_att = 0;
  45.         }
  46.        
  47.        
  48.        
  49.         if ( ((a*lim3*lim2) + (b*lim3) + f) < n_el) {
  50.            
  51.            
  52.             if (P[indice_att] == *(&X[0] + ((a*lim3*lim2) + (b*lim3) + f)) ) {
  53.                 indice_att = indice_att + 1;
  54.             } else {
  55.                 indice_att = 0;
  56.             }
  57.            
  58.            
  59.         }
  60.        
  61.     }
  62.    
  63.     cout << "V-fetta " << f << "=" << match << " match" << endl;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment