跟踪的最低编号的数组中的 [英] Keep track of the lowest numbers in an array

查看:56
本文介绍了跟踪的最低编号的数组中的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想保持最低数量的分数的轨道,如果我找到那些球员的得分最低,我不希望他们在下一轮再次发挥。我已经得到了到存储这些低价值的球员到阵列的点,但我只希望他们能够暂时存储。

 的for(int i = 0; I< player.length;我++){
  对于(INT J = 1; J< player.length; J ++){
     如果(播放器[J]<播放器[I]){
       分[I] = j的;
       的System.out.println(分[I] ++轮++ playerList.get(J));
            }
        }
    }


解决方案

做2单独的回路来代替。其中找到最低的数字,第二个收集索引。

  INT minValue(最小值)= 1000000; //
的for(int i = 0; I< player.length;我++){
  如果(播放器[1] - ; minValue(最小值)){
    minValue(最小值)=玩家[I]
  }
}
INT J = 0;
的for(int i = 0; I< player.length;我++){
  如果(播放器由[i] == minValue(最小值)){
    分[J] =我;
    J ++;
  }
}

I am trying to keep track of the the scores of the lowest numbers and if I find the lowest scores of those players I don't want them to play again in the next round. I have gotten to the point of storing those low player value into the array but I only want them to be stored ONCE.

 for(int i =0; i <  player.length; i++){
  for(int j =1; j <  player.length; j++){
     if(player[j] < player[i]){
       min[i] =j;
       System.out.println(min[i]+" "+round+" "+playerList.get(j));
            }
        }
    }

解决方案

Do 2 separate loops instead. One to find lowest number, second to collect indexes.

int minValue = 1000000; //
for(int i =0; i< player.length; i++){
  if(player[i] < minValue){
    minValue = player[i];
  }
}
int j =0;
for(int i =0; i< player.length; i++){
  if(player[i]==minValue){
    min[j]=i;
    j++;
  }
}

这篇关于跟踪的最低编号的数组中的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆