小编use*_*047的帖子

在地图C++中使用数组作为键

基本上,我需要找到所有匹配的字谜到一个单词.我正在做的是使用大小为26的数组来表示单词中的字母.例如:abcdefg = {1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0,0} aaaaaaa = {7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0}

这就是我创建数组的方式.

//stringtemp is a C++ string representing the word.
//letters is a size 26 int array representing all the letters in the string.
for(int i=0;i<stringtemp.length();i++)
{
    letters[stringtemp[i]-65]+=1;
}
Run Code Online (Sandbox Code Playgroud)

这就是我将数组存储在地图中的方式.

dictionary[letters].push_back(stringtemp);
Run Code Online (Sandbox Code Playgroud)

所以,我做错了什么,或者在C++中这是不可能的.在我发现的所有其他答案中,他们建议使用矢量作为关键,但这在我的情况下不起作用(我想.)

c++ arrays map

0
推荐指数
1
解决办法
9972
查看次数

标签 统计

arrays ×1

c++ ×1

map ×1