【去哪儿】血型遗传检测

题目描述

血型遗传对照表如下:

父母血型子女会出现的血型子女不会出现的血型
O与OOA,B,AB
A与OA,OB,AB
A与AA,OB,AB
A与BA,B,AB,O——
A与ABA,B,ABO
B与OB,OA,AB
B与BB,OA,AB
B与ABA,B,ABO
AB与OA,BO,AB
AB与ABA,B,ABO

请实现一个程序,输入父母血型,判断孩子可能的血型。

 

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

测试样例:

”A”,”A”
返回:[”A”,“O”]
class ChkBloodType {
public:
    vector<string> chkBlood(string father, string mother) {
        // write code here
       vector<string> ans;
       if(father.size()==mother.size()&&father.size()==1)
       {
               ans.push_back("O");
               if(father[0]=='O'&&mother[0]=='O')
               {    
               }
               else
               {
                   if(father[0]==mother[0])
                   {
                       string str;
                       ans.push_back(str+father[0]);
                   }
                   else
                   {
                        if(father[0]!='O'&&mother[0]!='O')
                        {
                              ans.push_back("A");
                              ans.push_back("B");
                              ans.push_back("AB");
                        }
                       else
                           ans.push_back(father[0]=='O'?mother:father);
                   }

               }
           
       }
        else
        {
            ans.push_back("A");
            ans.push_back("B");
            if(father[0]!='O'&&mother[0]!='O')
                ans.push_back("AB");           
        }
        sort(ans.begin(),ans.end());
        return ans;
    }
};

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值