Answer 1): Those pair stored in "vector<vector <int*>> good_vals" are nothing else than pointer to int inside the array n, therefore they store an address. If you where to print them without the dereference using this call
1 2 3 4 5 6 7 8 9 10 11
|
//PRINT
int ID{ 1 };
for (auto &v : good_vals)
{
cout << "Pair " << ID++ << ": ";
for (auto &e : v)
{
cout << e << " ";
}
cout << endl;
}
|
then you would get something like this
1 2
|
Pair 1: 012FFC70 012FFCB4
Pair 2: 012FFCB4 012FFC70
|
Now you can easily see we have 2 address that are the same, therefore you could have a loop that check each vector<int*> inside good_vals against each other vector<int*> of the same size() . To make your life easier, you also want to sort the pointers first, so 3-4 actually appear twice in that exact order (not sure if matters).
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
//SORT
for (auto &v : good_vals)
{
sort(v.begin(), v.end());
}
//ReMOVE DUPLICATES
for (size_t currentV = 0; currentV < good_vals.size(); currentV++)
{
for (size_t otherV = 0; otherV < good_vals.size(); otherV++)
{
//Don't check against itself
if (&good_vals[currentV] == &good_vals[otherV])
{
continue;
}
// == should check for equal size and equal elements inside the vectors
if (good_vals[currentV] == good_vals[otherV])
{
good_vals.erase(good_vals.begin() + otherV);
}
}
}
|
If you run that before the print, a pair of 3-4 will be gone.
Answer 2) Just pretty much the same thing from my previous example, but maybe instead of storing in a vector<vector<int*>> you use a map<vector<int*>, vector<string>> and this has a vector<string> inside because you'll keep the string with the 3 index for each element,maybe even better if you build a struct that associate the pointer and the string into a single object , so in the "//SELECT" phase I show you yesterday you also store the string generated from
|
mapped_vals[&n[A][B][C]] = to_string(A) + " " + to_string(B) + " " + to_string(C);
|
for each number in the pair , so basically you end up with a second "mapped_vals" kind of structure that hold the good vals pairs and all the string representing their indexes.
So now you only need a stringstream to extract the 3 pieces of information into 3 strings and convert them to int using std::stoi() and you use this A B C ints to access your other array in a loop.
Well, if I knew this was the thing you wanted to do, probably we could just have a struct storing the 3 indexes int in the beggining, without this super weird string workaround... xD