需要你的帮助。我有以下问题,例如我有一个公式,我可以检查一个站是否在每一行。我找到了它,但后来我需要每次检查,它可以是一行有10个站。然后我走一条线(multimap)创建一个线的名称以及该线上的站点。到目前为止我已经实现了以下代码。
multimap<int, int>numberofStation;
for (int newSt = 0; newSt <dimentionOfNewStation; newSt++)
{
int station = 0;
for (int Edges = 0; Edges < dimenstionOfEdges; Edges++)
{
float firstsol = 0;
float secondsol = 0;
float thirdsol = 0;
firstsol = (busEdges[Edges].y2 - busEdges[Edges].y1) / (busEdges[Edges].x2 - busEdges[Edges].x1);//check if a station on that line
secondsol = (apointCollection4[newSt].y- busEdges[Edges].y1) / (apointCollection4[newSt].x - busEdges[Edges].x1);//check if a station on that line
thirdsol = (busEdges[Edges].y2 - apointCollection4[newSt].y) / (busEdges[Edges].x2 - apointCollection4[newSt].x);//check if a station on that line
if (firstsol == secondsol && firstsol == thirdsol)//values should be the same
{
station = Edges;//i take that edge/line(id)
}
}
if (numberofStation.find(station) == numberofStation.end())
{
numberofStation.insert(pair<int, int>(station, newSt));//i add that station to that line
}
else
{
here i need to have a line of station for each line( 0 line has 2,5,3 station)
}
}
for (auto it = numberofStation.begin(); it != numberofStation.end(); it++)
{
and how i can print it out in the order i want above.
}
请告诉我,如果有可能这样的想法,或者它可能是非常疯狂,请告诉我如何做到这一点的方式。 所以这个想法,我需要找到每一行的站数。
提前致谢
答案 0 :(得分:0)
与selyunin一样,我不太确定你要求的是什么 也许它的std::equal_range()或(因为它无论如何都是多图){/ 3}}就像在
中一样std::multimap<int,int> m;
m.insert(pair<int, int>(0, 1));
m.insert(pair<int, int>(2, 2));
m.insert(pair<int, int>(1, 3));
m.insert(pair<int, int>(1, 4));
m.insert(pair<int, int>(0, 5));
m.insert(pair<int, int>(1, 6));
int station = 1;
// get the range of entries having (station) as "key"/first
auto r = m.equal_range(station);
while(r.first!=r.second) {
cout << (*(r.first)).second << ' ';
r.first++;
}
打印3 4 6