0

c++ 的初学者,我有两个数组。一个是字符串,另一个是二维数组(int)。如何将艺术家分配给乐谱?

int Artistlist()
{
    const int A1_SIZE = 5, A2_ROWSIZE =5, A2_COLSIZE =10;

    string Artist[A1_SIZE]={ "Degas", "Holbien", "Monet", "Matisse", "Valesquez" };

    int Scores[A2_ROWSIZE][A2_COLSIZE] =
    {
        {5,5,6,8,4,6,8,8,8,10},
        {8,8,8,8,8,8,8,8,8,8},
        {10,10,10,10,10,10,10,10,10,10},
        {5,0,0,0,0,0,0,0,0,0},
        {5,6,8,10,4,0,0,0,0,0}
    };
}
4

2 回答 2

1

您可以使用 std::map 和 std::vector。

std::map<std::string, std::vector<int>> map;

std::vector<int> DegasScores;
DegasScores.push_back(5);
DegasScores.push_back(5);
DegasScores.push_back(6);
DegasScores.push_back(8);
DegasScores.push_back(4);
DegasScores.push_back(6);
DegasScores.push_back(8);
DegasScores.push_back(8);
DegasScores.push_back(10);

map["Degas"] = DegasScores;
于 2013-09-16T17:32:27.920 回答
0

dude if the arrays are ordered correctly i think you should use

Artist[artistnum]
Scores[artistnum][0]
.
.
.
Scores[artistnum][9]

as John said.

于 2013-09-16T17:37:23.650 回答