日期:2014-05-18 浏览次数:20839 次
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class PingpongGame {
// 选手集
private static final List<String> teamA = new ArrayList<String>();
private static final List<String> teamB = new ArrayList<String>();
// 结果集:teamA队员为key,teamB队员为value
private static final Map<String, String> result = new HashMap<String, String>();
// 规则集:不允许集,teamA某个队员为key,不允许的对手名单列表为value
private static final Map<String, List<String>> noMap = new HashMap<String, List<String>>();
// 规则集初始化
static {
// 队员初始化
teamA.add("a");
teamA.add("b");
teamA.add("c");
teamB.add("x");
teamB.add("y");
teamB.add("z");
// a说他不和x比
List<String> aNoList = new ArrayList<String>();
aNoList.add("x");
noMap.put("a", aNoList);
// b的对手任意
List<String> bNoList = new ArrayList<String>();
noMap.put("b", bNoList);
// c说他不和x,z比
List<String> cNoList = new ArrayList&