Skip to content

Instantly share code, notes, and snippets.

@vieirin
Created December 20, 2018 07:26
Show Gist options
  • Save vieirin/3de09d6aaa6964fe28c161d18749dda0 to your computer and use it in GitHub Desktop.
Save vieirin/3de09d6aaa6964fe28c161d18749dda0 to your computer and use it in GitHub Desktop.
#include <vector>
#include <string>
#include <iostream>
struct tuple {
tuple(std::string name, int age) {
key = name;
value = age;
}
std::string key;
int value;
};
int getAge (std::vector<tuple> dict, std::string name){
for (auto i = dict.begin(); i < dict.end(); i++) {
if (i->key == name) {
return i->value;
}
}
return -1;
}
int main(int argc, char const *argv[])
{
std::vector<tuple> dict = {tuple("John", 32), tuple("Mary", 21), tuple("Josh", 40)};
std::cout << getAge(dict, "John") << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment