Advertisement
Guest User

Untitled

a guest
Sep 21st, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. int st[100], m[100]={ 0, 4, 5, 3 };
  7. int n, s, c;
  8.  
  9. struct feluri
  10. {
  11.     char nume[256];
  12.     int calorii;
  13.     double pret;
  14. };
  15.  
  16. struct mancaruri
  17. {
  18.     feluri fel[100];
  19.  
  20. }vector[100];
  21.  
  22. void citeste()
  23. {
  24.     ifstream fin("mancare.in");
  25.     fin >> s >> c;
  26.     for(int i=1; i<=n; i++)
  27.         for(int j=1; j<=m[i]; j++)
  28.         {
  29.             fin >> vector[i].fel[j].nume;
  30.             fin >> vector[i].fel[j].calorii;
  31.             fin >> vector[i].fel[j].pret;
  32.         }
  33.     fin.close();
  34. }
  35.  
  36. void init(int k)
  37. {
  38.     st[k] = 0;
  39. }
  40.  
  41. int succesor(int k)
  42. {
  43.     if(st[k] < m[k])
  44.     {
  45.         st[k] = st[k] + 1;
  46.         return 1;
  47.     }
  48.     else
  49.         return 0;
  50. }
  51.  
  52. int valid(int k)
  53. {
  54.     return 1;
  55. }
  56.  
  57. int solutie(int k)
  58. {
  59.     return n == k;
  60. }
  61.  
  62. void tipar(int k)
  63. {
  64.     int sumaC = 0;
  65.     int sumaP = 0;
  66.     for(int i = 1; i <= n; i++)
  67.     {
  68.         sumaP += vector[i].fel[st[i]].pret;
  69.         sumaC += vector[i].fel[st[i]].calorii;
  70.     }
  71.  
  72.     if(sumaC < c && sumaP < s)
  73.     {
  74.         for(int i=1; i<=n; i++)
  75.             cout << vector[i].fel[st[i]].nume << " ";
  76.         cout << "  | " << sumaP << "  | " << sumaC;
  77.         cout << '\n';
  78.     }
  79.  
  80. }
  81.  
  82. void bkt(int k)
  83. {
  84.     init(k);
  85.     while(succesor(k))
  86.     {
  87.         if(valid(k))
  88.         {
  89.             if(solutie(k))
  90.             {
  91.                 tipar(k);
  92.             }
  93.             else
  94.                 bkt(k+1);
  95.         }
  96.     }
  97. }
  98.  
  99. int main()
  100. {
  101.     n = 3;
  102.     citeste();
  103.     bkt(1);
  104.     return 0;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement