【发布时间】:2011-07-25 09:06:45
【问题描述】:
这是最后的手段..
所以我有两张地图。
typedef std::map <string, vector<float> > Dict;
typedef std::map <string, string> Dict1;
第一张地图的内容如下所示: 字典 = {A: -3.1, 2.1, 1.1}; {B: -4.5, 5.6, 7.2}...
第二个映射中的字符串与第一个映射中的键相同。 Dict1 = {A: B};...
我需要创建类似的东西:
Dict2 = {-3.1, 2.1, 1.1: -4.5, 5.6, 7.2}...
或两个将它们放在两个向量中,但有可能重建 Dict1 的结构。从技术上讲,这些是某些点的坐标。
我实际上走了第二条路线并尝试创建两个向量然后匹配它们,但是,显然我犯了一些错误..这是我所拥有的:
typedef std::map <string, vector<float> > Dict;
typedef std::map <string, string> Dict1;
typedef std::vector<float> V1;
V1 v1;
V1 v2;
Dict d;
Dict d1;
//Here is the code, I know, oh well...
for( map<string, vector<float> >::iterator iter0 = d.begin(); iter0 != d.end(); ++iter0 ) {
for( map<string, string >::iterator iter1 = d1.begin(); iter1 != d1.end(); ++iter1 ) {
vector <float> tempVal0 = (*iter0).second;
string tempKey0 = (*iter0).first;
string tempVal1 = (*iter1).second;
string tempKey1 = (*iter1).first;
size_t comp1 = tempKey0.compare(tempKey1);
if(comp1 == 0 ){
for (unsigned i = 2; i < tempVal0.size(); i++) {
v1.push_back(tempVal0[i-2]);
v1.push_back(tempVal0[i-1]);
v1.push_back(tempVal0[i]);
for( map<string, vector<float> >::iterator iter00 = d.begin(); iter00 != d.end(); ++iter00 ) {
for( map<string, string >::iterator iter11 = d1.begin(); iter11 != d1.end(); ++iter11 ) {
vector <float> tempVal00 = (*iter00).second;
string tempKey00 = (*iter00).first;
string tempVal11 = (*iter11).second;
string tempKey11 = (*iter11).first;
size_t comp2 = tempVal1.compare(tempKey00);
if (comp2 == 0){
for (unsigned i = 2; i < tempVal00.size(); i++) {
v2.push_back(tempVal00[i-2]);
v2.push_back(tempVal00[i-1]);
v2.push_back(tempVal00[i]);
}
}
}
}
}
}
}
}
我错过了什么??
【问题讨论】:
-
您能解释一下您需要以哪些方式执行查找吗?也许使用两个
boost.bimaps 而不是两个std::map已经可以解决您的问题了。