• 2016去哪儿编程题:5-血型遗传检测


    题目描述

    血型遗传对照表如下:

    父母血型子女会出现的血型子女不会出现的血型
    O与O O A,B,AB
    A与O A,O B,AB
    A与A A,O B,AB
    A与B A,B,AB,O ——
    A与AB A,B,AB O
    B与O B,O A,AB
    B与B B,O A,AB
    B与AB A,B,AB O
    AB与O A,B O,AB
    AB与AB A,B,AB O
    请实现一个程序,输入父母血型,判断孩子可能的血型。

     

    给定两个字符串fathermother,代表父母的血型,请返回一个字符串数组,代表孩子的可能血型(按照字典序排列)。

    测试样例:
    ”A”,”A”
    返回:[”A”,“O”]
    解题
    字典给你了,直接HashMap就可以了,注意,父母的血型互换后结果是一样的。
    import java.util.*;
    
    public class ChkBloodType {
        /**
        *请实现一个程序,输入父母血型,判断孩子可能的血型。
        * 都给了,判断取出可能血型
        */
        public String[] chkBlood(String father, String mother) {
            // write code here 
            HashMap<String,String[]> map = new HashMap<String,String[]>();
            map.put("OO", new String[] { "O" });
            map.put("AO", new String[] { "A", "O" });
            map.put("OA", new String[] { "A", "O" });
            map.put("AA", new String[] { "A", "O" });
            map.put("AB", new String[] { "A", "AB", "B", "O" });
            map.put("BA", new String[] { "A", "AB", "B", "O" });
            map.put("AAB", new String[] { "A", "AB", "B" });
            map.put("ABA", new String[] { "A", "AB", "B" });
            map.put("BO", new String[] { "B", "O" });
            map.put("OB", new String[] { "B", "O" });
            map.put("BB", new String[] { "B", "O" });
            map.put("BAB", new String[] { "A", "AB", "B" });
            map.put("ABB", new String[] { "A", "AB", "B" });
            map.put("ABO", new String[] { "A", "B" });
            map.put("OAB", new String[] { "A", "B" });
            map.put("ABAB", new String[] { "A", "AB", "B" });
                
            return map.get(father + mother );
            
        }
    }
     
  • 相关阅读:
    jQuery ajax解析xml文件demo
    Jquery ajax传递xml方式在ie8下兼容问题
    Ajax 跨域请求
    【leetcode刷题笔记】Maximal Rectangle
    【leetcode刷题笔记】Substring with Concatenation of All Words
    【leetcode刷题笔记】Largest Rectangle in Histogram
    【leetcode刷题笔记】Decode Ways
    【leetcode刷题笔记】3Sum Closest
    【leetcode刷题笔记】3Sum
    【leetcode刷题笔记】Divide Two Integers
  • 原文地址:https://www.cnblogs.com/theskulls/p/5384131.html
Copyright © 2020-2023  润新知