血型遗传对照表如下:
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
using namespace std;
map <vector <string>, set <string> > mp;//建立输入血型vector, 与输出可能会出现血型set之间联系的map
string f, m;//双方血型读取
vector <string> i; //建立输入血型vector
set <string> o;//可能会出现血型set
set <string> un;//不可能会出现血型set
map <vector <string>, set <string> > unmp;//建立输入血型vector, 与不可能会出现血型set之间联系的map
void table()
{
//将全部血型输入不可能会出现血型un这一set,当输出任意可能出现血型,使用erase()将un这一set里的该血型擦除
un.insert("AB");
un.insert("A");
un.insert("B");
un.insert("O");
//应该把f, m放到打表法里面么
if (f != "AB" || m != "AB")
{
o.insert("O");
un.erase("O");
o.insert(f);
un.erase(f);
o.insert(m);
un.erase(m);
}
if ( (f == "A" && m == "B") || (f == "B" && m == "A"))
{
o.insert("AB");
o.insert("A");
o.insert("B");
un.erase("AB");
un.erase("A");
un.erase("B");
}
if ( (f == "AB" && m != "O") || (m == "AB" && f!= "O"))
{
o.insert("A");
o.insert("B");
o.insert("AB");
un.erase("AB");
un.erase("A");
un.erase("B");
}
if ( (f == "AB" && m == "O") || (m == "AB" && f == "O") )
{
o.insert("A");
o.insert("B");
un.erase("A");
un.erase("B");
}
mp[i] = o;
unmp[i] = un;
}
int main()
{
/***********************************************
string f, m;
vector <string> v;
cin >> f >> m;//这样读会读入','
************************************************/
table();
string str;
cin >> str;
string a = "";
string b = "";
int bstart = 0;
for (int z = 0; z < str.length(); z++)
{
while (str[z] != ',')
{
a += str[z];
}
if (str[z] == ',')
{
bstart = z;
}
}
for (int z = bstart; z < str.length(); z++)
{
b+= str[z];
}
i.push_back(a);
i.push_back(b);
set <string> tempi;
set <string> tempo;
for (auto it = mp.begin(); it != mp.end(); it++)//注意这一句的写法auto it = .begin(); it != .end(); it++
{
tempi = *it;
for (int i = 0; i < tempi.size(); i++)
{
if (i == 0)
{
cout << tempi[i];
}
else
{
cout << "," << tempi[i];
}
}
}
for (auto it = unmp.begin(); it != unmp.end(); it++)//注意这一句的写法auto it = .begin(); it != .end(); it++
{
tempo = *it;
for (int i = 0; i < tempo.size(); i++)
{
if (i == 0)
{
cout << tempo[i];
}
else
{
cout << "," << tempo[i];
}
}
}
}
请实现一个程序,输入父母血型,判断孩子可能的血型。
给定两个字符串father和mother,代表父母的血型,请返回一个字符串数组,代表孩子的可能血型(按照字典序排列)。
测试样例:
”A”,”A”
返回:[”A”,“O”]