GastonFontenla

N2P2 - Recetas

Sep 1st, 2019
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int recetas(vector <string> heladera, vector <vector <string> > libro, vector <int> &realizables)
  6. {
  7.     set <string> h;
  8.     for(const auto &i:heladera)
  9.         h.insert(i);
  10.  
  11.     for(int i=0; i<libro.size(); i++)
  12.     {
  13.         bool estanTodos = true;
  14.         for(const auto &j:libro[i])
  15.         {
  16.             if(h.count(j) == 0)
  17.             {
  18.                 estanTodos = false;
  19.                 break;
  20.             }
  21.         }
  22.         if(estanTodos)
  23.             realizables.push_back(i+1);
  24.     }
  25.  
  26.     return realizables.size();
  27. }
  28.  
  29. /**
  30. //Funcion main auxiliar para testear
  31. int main()
  32. {
  33.     int H, P;
  34.     cin >> H >> P;
  35.     vector <string> heladera(H);
  36.     vector <vector <string> > libro(P);
  37.     for(int i=0; i<H; i++)
  38.         cin >> heladera[i];
  39.     for(int i=0; i<P; i++)
  40.     {
  41.         int cant;
  42.         cin >> cant;
  43.         libro[i].resize(cant);
  44.         for(int j=0; j<cant; j++)
  45.             cin >> libro[i][j];
  46.     }
  47.  
  48.     vector <int> realizables;
  49.     int res = recetas(heladera, libro, realizables);
  50.  
  51.     cout << res << endl;
  52.     for(int i=0; i<realizables.size(); i++)
  53.         cout << realizables[i] << " ";
  54.     cout << endl;
  55.  
  56.     return 0;
  57. }
  58. **/
Advertisement
Add Comment
Please, Sign In to add comment