首页 > 其他 > 详细

乒乓球队比赛,甲队有abc三人,乙队有xyz三人。 抽签得出比赛名单:a不和x比,c不和x,z比, 利用集合求出比赛名单

时间:2020-02-14 21:22:06      阅读:90      评论:0      收藏:0      [点我收藏+]
import java.util.HashMap;
import java.util.Map;

/**
 * 乒乓球队比赛,甲队有abc三人,乙队有xyz三人。
 * 抽签得出比赛名单:a不和x比,c不和x,z比,
 * 利用集合求出比赛名单
 * @author  努力coding
 * @version
 * @data    2020年2月
 */
public class FindTeam {
    public static void main(String[] args) {
        Map<Character,Character> stu = new HashMap<Character,Character>();
        /**假设a对x,b对y,c对z*/
        char a = 'x';
        char b = 'y';  
        char c = 'z';
        char temp;//临时变量
        
        //c不和x,z比
        for(temp = 'x'; temp <= 'z'; temp++) {
            if(temp != 'x' && temp != 'z') {
                c = temp;
                stu.put('c', c);//存入Map中
            }
        }
        
        //a不和x比
        for(temp = 'x'; temp <= 'z'; temp++) {
            if(temp != 'x' && temp != c) {
                a = temp;
                stu.put('a', a);
            }
        }
        
        //a和c的对手都已知,剩下的就是b的对手
        for(temp = 'x'; temp <= 'z'; temp++) {
            if(temp != a && temp != c) {
                b = temp;
                stu.put('b', b);
            }
        }
        System.out.println("比赛名单如下:");
        for(char key : stu.keySet()) {
            System.out.println(key + " VS " + stu.get(key));
        }
        
    }
}

乒乓球队比赛,甲队有abc三人,乙队有xyz三人。 抽签得出比赛名单:a不和x比,c不和x,z比, 利用集合求出比赛名单

原文:https://www.cnblogs.com/Zhouge6/p/12309445.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!