java中自定义对象排序(TreeSet)

package cn.csu.HappyCoding;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.TreeSet;
/**
 * 队伍比赛安排  涉及自定义对象的排序,TreeSet特性与应用
 * eg:10001:50+10002:45+10003:50+10004:43
 * @author Administrator
 *
 */
public class Alibaba3 {
    /** 请完成下面这个函数,实现题目要求的功能 **/
    /** 当然,你也可以不按照这个模板来作答,完全按照自己的想法来 ^-^  **/
  
    static ArrayList getMatch(String str) {
    	//字符串str格式定义为:队伍编号:队伍能力,多个队伍之间用加号连接,接下来对队伍比赛进行安排
    	//eg:str=10001:50+10002:45,表示两个队伍10001和10002,分别对应能力50和45
    	String[] teams = str.split("\\+");//切分出每一个队伍
    	TreeSet teamsInfo = new TreeSet();
    	for(int i = 0; i < teams.length;i++){
    		String[] teamInfo = teams[i].split(":");
    		teamsInfo.add(new Team(teamInfo[0], Integer.parseInt(teamInfo[1])));//将每一个队伍信息添加到TreeSet集合
    	}
    	Object[] array = teamsInfo.toArray();
    	ArrayList teamVs = new ArrayList();
    	for(int i = 0;i < array.length; i += 2){
    		Team team1 = (Team)array[i];
    		Team team2 = (Team)array[i+1];
    		teamVs.add(team1.getTeamNum()+" VS "+team2.getTeamNum());
    	}
    	return teamVs;
    }

    public static void main(String[] args){

        String s = new Scanner(System.in).next();  	
    	ArrayList res = getMatch (s);
    	
    	for(int i=0; i

你可能感兴趣的:(ACM,java,阿里巴巴)