fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. struct NumberName {
  6. int number;
  7. std::string name;
  8. operator int() const { return number; }
  9. operator std::string() const { return name; }
  10. };
  11.  
  12. std::vector<NumberName> gmap {
  13. {0, "respectable"},
  14. {1, "poor"},
  15. {400, "acceptable income"},
  16. {1000, "middle income"},
  17. {2000, "rich"}
  18. };
  19. std::string get_wealth(int salary) {
  20. return *(--upper_bound(begin(gmap), end(gmap), salary));
  21. }
  22.  
  23.  
  24.  
  25. int main() {
  26. std::cout << get_wealth(401) << '\n';
  27. }
Success #stdin #stdout 0.01s 5304KB
stdin
Standard input is empty
stdout
acceptable income