fork download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <functional>
  4. #include <map>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9. class translate {
  10. const map<vector<int>, char, function<bool(const vector<int>&, const vector<int>&)>> dictionary;
  11. public:
  12. translate() : dictionary({ { { 1, 2, 3, 4, 5 }, 'a' }, { { 5, 3, 7, 1 }, 'b' }, { { 3, 2, 5, 6, 8, 9, 0 }, 'z' } }, [](const auto& lhs, const auto& rhs){
  13. const auto its = mismatch(cbegin(lhs), cend(lhs), cbegin(rhs), cend(rhs));
  14.  
  15. return its.second != cend(rhs) && (its.first == cend(lhs) || *its.first < *its.second); }) {}
  16. char mapping(const vector<int>& key) {
  17. const auto it = dictionary.find(key);
  18.  
  19. return it == cend(dictionary) ? '\0' : it->second;
  20. }
  21. };
  22.  
  23. int main() {
  24. translate foo;
  25.  
  26. cout << foo.mapping({ 1, 2, 3, 4, 5 }) << endl;
  27. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
a