I need to have a key with multiple values. What datastructure would you recommend?

前端 未结 7 1142
悲哀的现实
悲哀的现实 2021-02-07 10:53

I have an string array filled with words from a sentence.

words[0] = \"the\"
words[1] = \"dog\"
words[2] = \"jumped\"
words[3] = \"over\"
words[4] = \"the\"
word         


        
7条回答
  •  死守一世寂寞
    2021-02-07 11:16

    You may also use unordered_map> which has some benefit over map structure. You can do such insertion if your dictionary is like 'c': "cat", 'c':"car", 'a':apple, 'a':"angus" :

    unordered_map> char_to_strings_map;
    //loop to traverse the dictionary : key:c, value:s
      char_to_strings_map[c].emplace_back(s);
    //loop ends
    

提交回复
热议问题