zoukankan      html  css  js  c++  java
  • 两个乒乓球队进行比赛,各出三人

    题目:两个乒乓球队进行比赛,各出三人。
    甲队为a,b,c三人,乙队为x,y,z三人。
    已抽签决定比赛名单。
    有人向队员打听比赛的名单。
    a说他不和x比,
    c说他不和x,z比,
    请编程序找出三队赛手的名单

    格式:
    c ps y

    import java.util.*;
    public class Test{
            //HashMap 存储选手被选中状态来做
            public static void main(String args[]){
                char[] m ={'c','a','b'};//甲队-先按提供信息详细程度把他们排好(容易的先入手)
                char[] n ={'x','y','z'};//乙队
                HashMap<Character,Integer> hm = new HashMap<Character,Integer>();//存储队员已有对手了吗
                //初始都没有对手
                hm.put('a',0);
                hm.put('b',0);
                hm.put('c',0);
                hm.put('x',0);
                hm.put('y',0);
                hm.put('z',0) ;
                for(int i=0;i<3;i++){
                    for(int j=0;j<3;j++){
                        if(i==1&&j==0)continue;
                        if(i==0&&(j==0||j==2))continue;
                        if(hm.get(m[i])==0&&hm.get(n[j])==0){
                        //都没有对手就把他们设成对手
                        //他们的状态改为已有对手
                        hm.remove(m[i]);
                        hm.put(m[i],1);
                        hm.remove(n[j]);
                        hm.put(n[j],1);
                        System.out.println(m[i]+" ps "+n[j]);
                    }
                }
            }
       }
    }
            /*---运行输出----
            c ps y
            a ps z
            b ps x
            */
  • 相关阅读:
    html 注释和特殊字符
    html 锚点链接
    html 链接标签
    spring 利用工厂模式解耦
    html 路径
    html 图像标签
    html div和span标签
    html 文本格式化标签
    P5358 [SDOI2019]快速查询
    luoguP2679 子串
  • 原文地址:https://www.cnblogs.com/laoquans/p/2963322.html
Copyright © 2011-2022 走看看