【发布时间】:2012-09-15 15:22:07
【问题描述】:
基本上,我需要找到一个单词的所有匹配字谜。我正在做的是使用一个大小为 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}
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}
这就是我创建数组的方式。
//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;
}
这就是我在地图中存储数组的方式。
dictionary[letters].push_back(stringtemp);
那么,我做错了什么还是在 C++ 中这是不可能的。在我找到的所有其他答案中,他们建议使用向量作为键,但这不适用于我的情况(我认为。)
【问题讨论】:
-
正如下面的答案所反映的,C 风格的数组不会像您期望的那样复制。
-
包含
dictionary和letters的定义会有所帮助。
标签: c++ arrays dictionary