Basically a 1 appears for each number listed in the previous list, otherwise zero is shown.
Could anybody assist with attempting the transformation?
My code is as follows:
#include <iostream>
#include <map>
#include <sstream>
#include <iomanip>
int digit_count(int number) {
int digits = 0;
if (number < 0) digits = 1; // remove this line if '-' counts as a digit
while (number) {
number /= 10;
digits++;
}
return digits;
}
int main () {
unsignedshort v1,v2;
std::istringstream stm {"1 2 2 3 3 1 4 1 4 5 5 3 5 6 6 4 "};
std::map<unsignedshort, std::map <unsignedshort, unsignedshort> > m;
while (stm >> v1 >> v2) {
m[v1]; m[v2]; // create the key(s), v2 required as well in case there are no outbounds
m[v1][v2] = 1; // set the value
}
int dc = digit_count(m.rbegin()->first); // equals 10
std::string ss = "";
for (constauto & p : m) {
std::cout << p.first << ss.append(" ", (dc - digit_count(p.first))) << "|";
for (constauto & x : p.second)
std::cout << x.first << " ";
ss = "";
std::cout << "\n";
}
return 0;
}