For any particular country, you might have an array to represent the row that holds the medal counts. Each column in a row would be associated with gold, silver, or bronze.
Ignoring country for now, you might do something like:
// Hold all the medal values
std::vector<std::array<int, 3>> medal_table;
// Skip title line
std::string line;
std::getline(std::cin, line);
std::string country;
int gold, silver, bronze;
while (std::cin
>> country
>> gold
>> silver
>> bronze) {
std::array<int, 3> row{gold, silver, bronze};
medal_table.push_back(row);
}
Note: the parsing of the country isn't perfect, because some of the country names actually consist of two strings. I'll leave solving that as an exercise.
But, we have now lost the association between the country and the medal counts. You could create another vector to manage that. For example:
std::vector<std::string> country_table;
And then, inside the loop, push the country value in when you push in the row.
medal_table.push_back(row);
country_table.push_back(country);
Now, there is a correspondence between the rows in medal_table
and the rows in country_table
.
The disadvantage of this approach is that if you want to know the medal counts for a particular country, you will have to scan country_table
first to find the country. The found index in country_table
is then used on medal_table
to find the medal counts.
If you can move away from a strictly 2 dimensional array into one that allows 2 dimensional indexing, you can directly map a country name to the row representing the medal counts.
std::map<std::string, std::array<int, 3>> medal_map;
Then, instead of populating corresponding arrays, you can populate a single map.
medal_map[country] = row;
Now, to find the medal counts for a particular country, you simply index medal_map
by the name of the country.