c++如何实现二维队列?

问题是,现在有一段字符串,我要搜索找出里面的重复的字母,和他们的下标。比如:
abcaabbcd
建立成表:
a 0 3 4
b 1 5 6
c 2 7
因为重复字母个数不定,重复的下标数也不确定。各位能不能想到什么办法实现呢?

先对字符串进行一个排序,然后遍历一次就能找到重复的字母和对应重复的次数了

// 建议使用C++的map实现
#include
#include
#include
void count(std::map >& mapWord2Index, const std::string& strWords)
// mapWord2Index为统计结果
// strWords为要统计的字符串
{
for(int i = 0; i < strWords.length(); ++i)
{
mapWord2Index[strWords[i]].push_back(i);
}
}

这篇文章应该可以帮你解决问题:http://blog.csdn.net/autocyz/article/details/42391155

逻辑比较简单,可以自定义数据结构,至于不定个数的索引值序列,可以用std::vector(变长数组)

class searchRecord
{
    char cValue;
    std::vector<int> vecIndex;
};

最简单的办法就是用multimap:

 std::multimap<char, int> indices;

 // put each index of char c, index i:
 indices[c] = i;

 // count number of c:
 indices.count(c);

 // find first index of c:
 std::multimap<char, int>::iterator it = indices.find(c);

做一个MAP std::map >, 以字母为key,下标为vector的值,得到结果是,如果value(即vector的大于1,则说明重复,)vector的值就是重复下表。