This can be done with a std::priority_queue, which automatically sorts the entries. With the data sorted like this, one only has to count the number of subsequent identical entries:
#include <queue>
#include <iostream>
#include <vector>
#include <utility> // for std::pair
int main() {
std::priority_queue<std::pair<int,int>> mydat;
mydat.push(std::make_pair(10,8));
mydat.push(std::make_pair(11,7));
mydat.push(std::make_pair(10,8));
mydat.push(std::make_pair(10,8));
mydat.push(std::make_pair(15,12));
mydat.push(std::make_pair(11,7));
std::vector<std::vector<int>> out;
std::pair<int,int> previous;
int counter;
while(!mydat.empty()) {
counter = 1;
previous = mydat.top();
mydat.pop(); // move on to next entry
while(previous == mydat.top() && !mydat.empty()) {
previous = mydat.top();
mydat.pop();
counter++;
}
out.push_back({previous.first, previous.second, counter});
}
for(int i = 0; i < out.size(); ++i) {
std::cout << out[i][0] << " " << out[i][1] << " " << out[i][2] << std::endl;
}
}
godbolt demo
Output:
15 12 1
11 7 2
10 8 3