fork download
  1. #include <algorithm>
  2. #include <map>
  3. #include <string>
  4. #include <vector>
  5. #include <iostream>
  6.  
  7. using namespace std;
  8.  
  9. bool subject_is_done(string sbj, const map<string, vector<string>>& dates)
  10. {
  11. for (auto& p : dates)
  12. {
  13. if (find(p.second.begin(), p.second.end(), sbj) != p.second.end())
  14. return true;
  15. }
  16. return false;
  17. }
  18.  
  19. bool maestro_is_free(const pair<string, vector<string>>& p,
  20. const pair<string, vector<string>>& date)
  21. {
  22. for (auto& sbj : p.second)
  23. {
  24. if (find(date.second.begin(), date.second.end(), sbj) != date.second.end())
  25. return false;
  26. }
  27. return true;
  28. }
  29.  
  30. int main()
  31. {
  32. map<string, vector<string>> subjects;
  33. map<string, vector<string>> dates;
  34.  
  35. dates["2.9. Montag"];
  36. dates["3.9. Dienstag"];
  37. dates["4.9. Mittwoch"];
  38. dates["5.9. Donnerstag"];
  39. dates["6.9. Freitag"];
  40.  
  41. subjects["Mister A"] = {"Deutsch", "Religion", "Chemie"};
  42. subjects["Mister B"] = {"Deutsch", "Sport", "Informatik"};
  43. subjects["Mister C"] = {"Mathe", "Physik", "Informatik"};
  44. subjects["Mister X"] = {"Englisch", "Biologie", "Chemie"};
  45.  
  46. for (auto& date : dates)
  47. {
  48. for (auto& p : subjects)
  49. {
  50. for (auto& sbj : p.second)
  51. {
  52. // Ekliger Hack, aber was soll's
  53. if (!subject_is_done(sbj, dates) && maestro_is_free(p, date))
  54. {
  55. date.second.push_back(sbj);
  56. }
  57. }
  58. }
  59. }
  60.  
  61. for (auto& p : dates)
  62. {
  63. std::cout << p.first << ": ";
  64. for (auto& sbj : p.second)
  65. {
  66. std::cout << sbj << ", ";
  67. }
  68. std::cout << '\n';
  69. }
  70. }
Success #stdin #stdout 0s 3484KB
stdin
Standard input is empty
stdout
2.9. Montag: Deutsch, Mathe, Englisch, 
3.9. Dienstag: Religion, Sport, Physik, Biologie, 
4.9. Mittwoch: Chemie, Informatik, 
5.9. Donnerstag: 
6.9. Freitag: