C++ vector<vector<int>>`select only entries that appear just once -
i have vector<vector<int>>
has following entries:
2 3
3 4
2 3
4 5
5 6
i need create vector<vector<int>>
entries apeears once. so:
3 4
4 5
5 6
this gives result looking for. using std::map
, std::pair
#include <iostream> #include <vector> #include <map> int main() { std::map<std::pair<int, int>, int> count_map; std::vector<std::pair<int, int> > v; std::vector<std::pair<int, int> > v2; int a[10] = {2,3,3,4,2,3,4,5,5,6}; for(int = 0; < 10; i++) { int first = a[i]; int second = a[++i]; std::pair<int, int> p = std::make_pair(first, second); v.push_back(p); count_map[p]++; } for(auto = count_map.begin(); != count_map.end(); ++it) { if(it->second != 1) continue; v2.push_back(it->first); std::cout << it->first.first << ", " << it->first.second << std::endl; } }
Comments
Post a Comment