그것은 당신이 무슨 뜻인지 정확히 분명하지 않다 : 당신은 당신이 원하는 같은 이름의 목록을 삽입 할 경우 (배열 포함)는 다음과 같이 할 것 그들과 관련이 있어야합니다. 또한 이름이 고유한지 여부는 밝히지 않았습니다. 당신은 이름이 방법을 페어 (pair) 할 수 있습니다
: 다음
String input = "Joe, Bob, Andrew, Bill, Charlie, Sarah, Ann, Victor";
String names[] = input.split(",");
Map<String, String> output = new HashMap<String, String>();
for (int i=0; i<names.length; i+=2) {
output.put(names[i].trim(), names[i+1].trim());
}
및 수행
String input = "Joe, Bob, Andrew, Bill, Charlie, Sarah, Ann, Victor";
String names[] = input.split(",");
Map<String, String> output = new HashMap<String, String>();
for (int i=0; i<names.length; i+=2) {
String first = names[i].trim();
String second = names[i+1].trim();
output.put(first, second);
output.put(second, first);
}
: 당신은 또한 조와 함께 밥을 연결해야하는 경우
output.remove("Joe"); // Joe is paired with Bob
, 당신은 이런 식으로 할 수
다음으로 수행 :
String other = output.remove("Joe");
output.remove(other);
일반 영어로 알고리즘의 논리를 설명해 주시겠습니까? 이름은 어떻게 매핑됩니까? 벡터는 어디에 있습니까? –
안녕하세요, 게시글을 수정했습니다. 명확하지 않다면 죄송합니다 – Andrey