#include <map>
#include <vector>
#include <string>
#include <iostream>
#include <stdexcept>
typedef std::string Object;

int main() {
    std::vector<std::string> names;
    names.push_back(std::string("A"));
    names.push_back(std::string("A"));
    names.push_back(std::string("B"));
    names.push_back(std::string("C"));
    names.push_back(std::string("A"));

    Object* ptr_A = new Object("APPLE");
    Object* ptr_B = new Object("BANANA");
    Object* ptr_C = new Object("CARROT");

    std::vector<Object*> objects;
    
// ANSWER
typedef std::map<std::string, Object*>::iterator iterator;
typedef std::pair<std::string, Object*> value_type;
std::map<std::string, Object*> lookup;  //or maybe unordered_map
lookup.insert(value_type("A", ptr_A));
lookup.insert(value_type("B", ptr_B));
lookup.insert(value_type("C", ptr_C));

for(int i=0; i<names.size(); ++i) {
    iterator iter = lookup.find(names[i]);
    if (iter == lookup.end())
         throw std::runtime_error("invalid name in file");
    objects.push_back(iter->second);
}
// END ANSWER

    for(int i=0; i<objects.size(); ++i)
        std::cout << *objects[i] << '\n';
}