小编noo*_*guy的帖子

查找数组中的最小值

我有两个数组:

int playerSums[9] = { };
string playerNames[9] = { };
Run Code Online (Sandbox Code Playgroud)

我试图获取数组中的最小值playerSums以及该值的数组索引

到目前为止,这是我尝试过的:

if (playerNames[index] == "End" || playerNames[index] == "end") {
    int lowestValue = playerSums[0];
    for (i = 1; i < sizeof(playerSums) / sizeof(playerSums[0]); i++) {
        if (playerSums[i] < lowestValue || lowestValue != 0)
            lowestValue = playerSums[i]; 
    }
    cout << index[playerNames] << " had the lowest values and got the sum ";
    cout << lowestValue << endl;
}
Run Code Online (Sandbox Code Playgroud)

playerSums例如,如果只有 3 个玩家在玩,即仅填充了数组的 …

c++ arrays algorithm iterator min

4
推荐指数
2
解决办法
2万
查看次数

标签 统计

algorithm ×1

arrays ×1

c++ ×1

iterator ×1

min ×1