AlenAntonelli

Problema 4

Aug 11th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int buscar (string a, string b)
  6. {
  7.     int tamA = a.size();
  8.     int tamB = b.size();
  9.    
  10.     if (tamA>tamB)
  11.         return 0;
  12.  
  13.     int cant = 0;
  14.     bool hay;
  15.  
  16.     for (int i=0; i<=tamB-tamA; i++)
  17.     {
  18.         hay = true;
  19.  
  20.         for(int j=0; j<tamA; j++)
  21.             if (a[j] != b[i+j] )
  22.                 hay = false;
  23.  
  24.         if (hay)
  25.             cant++;
  26.     }
  27.  
  28.     return cant;
  29. }
  30.  
  31. int main ()
  32. {
  33.     int L, Q;
  34.  
  35.     cin>>L;
  36.     vector <string> lista (L);
  37.  
  38.     for (int i=0; i<L; i++)
  39.         cin>>lista[i];
  40.  
  41.     cin>>Q;
  42.     vector <string> sub(Q);
  43.     vector <int> resp(Q, 0);
  44.  
  45.     for (int i=0; i<Q; i++)
  46.         cin>>sub[i];
  47.  
  48.  
  49.     for (int i=0; i<Q; i++)
  50.     {
  51.         for (int j=0; j<L; j++)
  52.             resp[i] += buscar( sub[i], lista[j] );
  53.  
  54.         cout<<resp[i]<<endl;
  55.     }
  56.  
  57.     return 0;
  58. }
Add Comment
Please, Sign In to add comment