나는 다가오는 Fifa 토너먼트를 가지고 있으며 가능한 매치업을 프린트하는 프로그램을 작성했습니다. 문제는 논리적으로 정렬되지 않아 일부 플레이어는 5-6 개의 순차적 게임을해야하고 다른 플레이어는 6 개의 게임을 기다려야한다는 것을 의미합니다. 다음 결과를 얻고 싶습니다 :논리적으로 분류 된 토너먼트 비품
player 1 - player 2
player 3 - player 4
player 5 - player 6
player 1 - player 3
player 2 - player 4
등등.
public class Fifa {
public static void main(String[] args) {
String[] players= {"Jens", "Dane", "Keppens", "Roel", "John", "Onslo", "JonasDB", "Bellon", "Sander"};
String[] players2 = {"Jens", "Dane", "Keppens", "Roel", "John", "Onslo", "JonasDB", "Bellon", "Sander"};
Multimap<String, String> fixtures = LinkedHashMultimap.create();
for(int i = 0; i < players.length; i++){
for (int j = 0; j < players.length; j++){
if(!players[i].equals(players2[j])) {
if(!fixtures.containsKey(players2[j]))
fixtures.put(players[i], players2[j]);
}
}
}
for(Map.Entry map : fixtures.entries()){
String key = map.getKey().toString();
Object value = map.getValue();
System.out.println(key + " - " + value);
}
그러나 여기이 출력합니다 것입니다 : 이것은 내가 지금 무엇을 가지고 내가 같은 값으로 여러 키를 필요로했기 때문에
Jens - Dane
Jens - Keppens
Jens - Roel
Jens - John
Jens - Onslo
Jens - JonasDB
Jens - Bellon
Jens - Sander
Dane - Keppens
Dane - Roel
Dane - John
Dane - Onslo
Dane - JonasDB
Dane - Bellon
Dane - Sander
Keppens - Roel
Keppens - John
Keppens - Onslo
Keppens - JonasDB
Keppens - Bellon
Keppens - Sander
Roel - John
Roel - Onslo
Roel - JonasDB
Roel - Bellon
Roel - Sander
John - Onslo
John - JonasDB
John - Bellon
John - Sander
Onslo - JonasDB
Onslo - Bellon
Onslo - Sander
JonasDB - Bellon
JonasDB - Sander
Bellon - Sander
은 내가 Multimap과를 사용했다.
때이 서로에 대한 3 플레이를합니까? 그들은 할? 1-2, 2-3, 3-4, 4-5, 5-6, 1-3, 2-4 등도 좋을까요? 왜냐하면 그것은 인덱스 대신 거리를 반복함으로써 매우 쉽게 수행 될 수 있기 때문입니다. – Dukeling
그들은 결국 서로 맞을 것입니다. 그 정렬 논리에 대한 "이슈"는 연속적인 게임을하는 플레이어가 항상 존재한다는 것이지만, 구현이 더 나은 것입니다. 어떻게 구현할 것인가? – Audiosleef