gpt4 book ai didi

c - 将数组按照从最小到最大的顺序排序 C

转载 作者:行者123 更新时间:2023-11-30 15:35:19 24 4
gpt4 key购买 nike

所以现在我的程序只是存储我输入 SIZE 次的最低值,有人可以帮我解决这个问题吗?我认为针对“最终”测试值可以解决此问题。

int least_to_greatest(int *scores){
int least_to_greatest[SIZE], a, b, c, n, low = 101, duplicate = 0, final = 0;

for (a = 0; a < SIZE; a++){ //assign low values to least_to_greatest[a]
for (b = 0; b < SIZE; b++){ //chose low values of score
if (scores[b] == low){ //deals with duplicates
duplicate++;
}
if (scores[b] < low && scores[b] > final){ //assigns new lowest value to low as long as it's larger than previous low value
low = scores[b];
duplicate = 0;
}
}
final = low; //final low value
least_to_greatest[a] = final;
if (duplicate > 0){ //deals with duplicates
for (c = 0; c < duplicate; c++){
a++;
least_to_greatest[a] = final;
}
}
}

for (n = 0; n < SIZE; n++){
if (!(n % 5)){
printf("\n"); //creates a newline after 5 values
}
printf("%d ", least_to_greatest[n]); //prints scores in least to greatest
}
getchar();

}

最佳答案

在每个“b”循环开始之前,您需要将重复值设置为 0,并将低值设置为 101。

关于c - 将数组按照从最小到最大的顺序排序 C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22976915/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com