That snippet seems very wrong to me.. I don't know why Peter87 did not mention any of it so I'm not sure that I'm correct myself. So don't rely on what I say because I'm a newbie and I haven't used maps that much. These are just thoughts.
map<string,vector<int,greater<int>>>m;
I'm not sure what you were trying to do here. What is "greater" supposed to be/do? The compiler is looking for a structure defined under the identifier "greater" with that line.
Proper way to declare two dimensional array:
vector < vector<int> >;
Sorting is to be done afterwards.
So,
map <string, vector < vector<int> >>m;
would create a mapping of string to 2D vector.
But this has no elements yet!!
So calling an index of the mapping
m[str]
would be illegal because it currently has 0 indexes.
m[str].push_back(value);
I have no clue what you were trying to do in this line..
1) m[str] is illegal like I said
2) std::map doesn't have member function .push_back()
3) value is of type int, so if you were to push it, where??
std::insert() is used to insert elements to a map.
In
1 2 3 4 5 6 7
|
for(auto x:m[it->first])
{
i++;
sum+=x;
if(i==3)
break;
}
|
for(auto x:m[it->first])
should be
for(auto x: m)
sum+=x;
should be
sum+=x.first;
Note that it's not x is not a pointer.