fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <algorithm>
  5.  
  6. struct Suit {
  7. std::string id;
  8. int height;
  9. int minChest, maxChest;
  10. int minWaist, maxWaist;
  11. int minHip, maxHip;
  12. int shoe;
  13. };
  14.  
  15. struct MatchResult {
  16. Suit suit;
  17. int matchCount;
  18. std::string failParams;
  19. };
  20.  
  21. bool compareResults(const MatchResult &a, const MatchResult &b) {
  22. return a.matchCount > b.matchCount;
  23. }
  24.  
  25. int main() {
  26. std::vector<Suit> suits = {
  27. {"F1", 168, 91, 96, 77, 81, 93, 99, 8},
  28. {"F2", 178, 117, 122, 89, 96, 117, 122, 8},
  29. {"F3", 175, 96, 102, 76, 81, 107, 112, 8},
  30. {"F4", 175, 101, 107, 81, 89, 112, 117, 6},
  31. {"F5", 165, 89, 91, 69, 71, 97, 101, 5},
  32. {"S1", 168, 90, 96, 76, 81, 90, 96, 7},
  33. {"S2", 168, 90, 96, 76, 81, 90, 96, 7},
  34. {"M1", 178, 101, 106, 86, 91, 102, 107, 9},
  35. {"M2", 178, 101, 107, 84, 89, 97, 101, 9},
  36. {"M3", 173, 98, 104, 81, 86, 96, 102, 8},
  37. {"M4", 178, 101, 106, 86, 91, 102, 107, 9},
  38. {"M6", 173, 98, 104, 81, 86, 96, 102, 7},
  39. {"L1", 188, 107, 112, 91, 97, 107, 112, 10},
  40. {"L2", 188, 107, 112, 91, 97, 107, 112, 12},
  41. {"L3", 183, 107, 112, 91, 97, 107, 112, 10}
  42. };
  43.  
  44. int user_height, user_chest, user_waist, user_hip, user_shoe;
  45. std::cout << "Height (cm): ";
  46. std::cin >> user_height;
  47. std::cout << "Chest (cm): ";
  48. std::cin >> user_chest;
  49. std::cout << "Waist (cm): ";
  50. std::cin >> user_waist;
  51. std::cout << "Hip (cm): ";
  52. std::cin >> user_hip;
  53. std::cout << "Shoe size (UK): ";
  54. std::cin >> user_shoe;
  55.  
  56. std::vector<MatchResult> results;
  57. for (const auto& suit : suits) {
  58. bool height_ok = (user_height <= suit.height);
  59. bool chest_ok = (user_chest >= suit.minChest && user_chest <= suit.maxChest);
  60. bool waist_ok = (user_waist >= suit.minWaist && user_waist <= suit.maxWaist);
  61. bool hip_ok = (user_hip >= suit.minHip && user_hip <= suit.maxHip);
  62. bool shoe_ok = (user_shoe <= suit.shoe);
  63.  
  64. int matchCount = (height_ok ? 1 : 0) + (chest_ok ? 1 : 0) +
  65. (waist_ok ? 1 : 0) + (hip_ok ? 1 : 0) +
  66. (shoe_ok ? 1 : 0);
  67.  
  68. std::string fails;
  69. if (!height_ok) { if (!fails.empty()) fails += ", "; fails += "Height"; }
  70. if (!chest_ok) { if (!fails.empty()) fails += ", "; fails += "Chest"; }
  71. if (!waist_ok) { if (!fails.empty()) fails += ", "; fails += "Waist"; }
  72. if (!hip_ok) { if (!fails.empty()) fails += ", "; fails += "Hip"; }
  73. if (!shoe_ok) { if (!fails.empty()) fails += ", "; fails += "Shoe"; }
  74.  
  75. results.push_back({suit, matchCount, fails});
  76. }
  77.  
  78. std::vector<MatchResult> perfectMatches;
  79. for (const auto &r : results) {
  80. if (r.matchCount == 5)
  81. perfectMatches.push_back(r);
  82. }
  83.  
  84. if (!perfectMatches.empty()) {
  85. std::cout << "\nPerfect fit:\n";
  86. for (const auto &p : perfectMatches)
  87. std::cout << " - " << p.suit.id << "\n";
  88. } else {
  89. std::cout << "\nNo perfect fit\n";
  90. }
  91.  
  92. std::sort(results.begin(), results.end(), compareResults);
  93.  
  94. std::vector<MatchResult> bestFits;
  95. for (const auto &r : results) {
  96. if (r.matchCount < 5)
  97. bestFits.push_back(r);
  98. }
  99.  
  100. if (!bestFits.empty()) {
  101. std::cout << "\nBest fits:\n";
  102. int count = 0;
  103. for (const auto &b : bestFits) {
  104. if (count >= 3) break;
  105. std::cout << " - " << b.suit.id;
  106. if (!b.failParams.empty())
  107. std::cout << " (" << b.failParams << ")";
  108. std::cout << "\n";
  109. count++;
  110. }
  111. }
  112.  
  113. return 0;
  114. }
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
Height (cm): Chest (cm): Waist (cm): Hip (cm): Shoe size (UK): 
No perfect fit

Best fits:
  - F1 (Height, Chest, Waist, Hip, Shoe)
  - F2 (Height, Chest, Waist, Hip, Shoe)
  - F3 (Height, Chest, Waist, Hip, Shoe)