Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include <string.h>
- using namespace std;
- bool fetta_vuota(int f, int n_el);
- void match_fetta(int* X, int lim1, int lim2, int lim3, int n_el, int f, int*P, int dimP);
- main()
- {
- int X[400]={},P[50], n_el, dimP, lim1,lim2,lim3;
- memset((void*)&X[0], 0, sizeof(X));
- cin>>lim1>>lim2>>lim3;
- cin>>n_el;
- for(int i=0; i<n_el; i++)
- cin >> X[i];
- cin>>dimP;
- for(int i=0; i<dimP; i++)
- cin>>P[i];
- for(int f=0; f<lim3 && !fetta_vuota(f,n_el); f++)
- match_fetta(X, lim1,lim2,lim3,n_el,f, P, dimP);
- cout<<"end"<<endl;
- }
- bool fetta_vuota(int f, int n_el)
- {
- return (f >= n_el);
- }
- void match_fetta(int* X, int lim1, int lim2, int lim3, int n_el, int f, int*P, int dimP) {
- int match = 0;
- int indice_att = 0;
- for (int a = 0; a < lim1; a++)
- for (int b = 0; b < lim2; b++)
- {
- if (indice_att == (dimP )) {
- match++;
- indice_att = 0;
- }
- if ( ((a*lim3*lim2) + (b*lim3) + f) < n_el) {
- if (P[indice_att] == *(&X[0] + ((a*lim3*lim2) + (b*lim3) + f)) ) {
- indice_att = indice_att + 1;
- } else {
- indice_att = 0;
- }
- }
- }
- cout << "V-fetta " << f << "=" << match << " match" << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment