Created
December 20, 2018 07:26
-
-
Save vieirin/3de09d6aaa6964fe28c161d18749dda0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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