1201 STL応用(血液型組合せ問題)
1201 STL応用(血液型組合せ問題)
STL(標準テンプレートライブラリ)は、多くのコンピュータ科学分野でよく使われている基本データ構造と基本アルゴリズムを含む効率的なC++プログラムライブラリです.STLはタイプパラメータ化されたプログラム設計方法であり,STLの使用によりコード多重化をよりよく実現できる.STLプログラミングではコンテナ(container)が汎用的なデータ構造である.コンテナは異なるタイプのデータオブジェクトを運ぶために使用され、現実の生活の中で、人々がコンテナを使って様々なものを積むように使用されているが、C++のコンテナにはデータオブジェクトを加工する金型のように、異なるタイプのデータをこの金型に置いて加工処理することができる「データ加工能力」がある.一定の共通特性を持つデータ構造を形成します.**
ヒント:従来の血液型ペアリングテーブルに基づいて、適切なSTL中の容器を選択して設計し、両親の血液型に対してベクトルVectorを用いて記憶し、子供が現れる可能性のある血液型と現れるべきでない血液型に対して集合Setを用いて記憶し、さらに親の血液型と子供ができるか不可能な血液型をパッケージ処理し、mapコンテナによるストレージ
出力要求*例えば:親血液型(A+A)子供の血液型(A、O)子供にあるまじき血液型(B、AB)Input A,O Output Possible blood type:A O Impossible blood type:AB B Sample Input A,O Sample Output Possible blood type:A O Impossible blood type:AB B
STL(標準テンプレートライブラリ)は、多くのコンピュータ科学分野でよく使われている基本データ構造と基本アルゴリズムを含む効率的なC++プログラムライブラリです.STLはタイプパラメータ化されたプログラム設計方法であり,STLの使用によりコード多重化をよりよく実現できる.STLプログラミングではコンテナ(container)が汎用的なデータ構造である.コンテナは異なるタイプのデータオブジェクトを運ぶために使用され、現実の生活の中で、人々がコンテナを使って様々なものを積むように使用されているが、C++のコンテナにはデータオブジェクトを加工する金型のように、異なるタイプのデータをこの金型に置いて加工処理することができる「データ加工能力」がある.一定の共通特性を持つデータ構造を形成します.**
ヒント:従来の血液型ペアリングテーブルに基づいて、適切なSTL中の容器を選択して設計し、両親の血液型に対してベクトルVectorを用いて記憶し、子供が現れる可能性のある血液型と現れるべきでない血液型に対して集合Setを用いて記憶し、さらに親の血液型と子供ができるか不可能な血液型をパッケージ処理し、mapコンテナによるストレージ
出力要求*例えば:親血液型(A+A)子供の血液型(A、O)子供にあるまじき血液型(B、AB)Input A,O Output Possible blood type:A O Impossible blood type:AB B Sample Input A,O Sample Output Possible blood type:A O Impossible blood type:AB B
cpp
#include
#include
using namespace std;
string disassemble(string blood)// ,eg:A,A A A
{
char charater[2];
if(blood=="B")
blood="OB";
if(blood=="A")
blood="OA";
if(blood=="O")
blood="OO";
return blood;
}
string test(string temp)//
{
if(temp=="BA"||temp=="AB") temp="AB";
else if(temp=="AA"||temp=="OA"||temp=="AO") temp= "A";
else if(temp=="BB"||temp=="OB"||temp=="BO") temp= "B";
else if(temp=="OO") temp="O";
return temp;
}
int main()
{
string father="",mather="",temp;int gg=0;
cin>>temp;
for(int i=0;i<temp.length();i++) //
{
if(temp[i]!=','&& gg==0)
father+=temp[i];
else
{
if(gg==0)
{
gg=1;
i++;
}
mather+=temp[i];
}
}
vector<string> parents[2];
parents[0].push_back(disassemble(father));
parents[1].push_back(disassemble(mather));//
string ch1= parents[0].back();
string ch2= parents[1].back();
string H1=ch1;
string H2=ch2;
set<string> PosBle,ImPoBle;// set
for(int i=0;i<=1;i++)
for(int j=0;j<=1;j++) // , test
{
char a[2];
a[0]=H1[i];
a[1]=H2[j];
string G(a,a+2);
temp = test(G); //01 10 11
PosBle.insert(temp);
}
gg=0;
cout<<"Possible blood type:";
// int n = PosBle.size();
ImPoBle.insert("AB");
ImPoBle.insert("A");
ImPoBle.insert("B");
ImPoBle.insert("O");
for(string j:PosBle)
{
cout<<j<<" ";
ImPoBle.erase(j);
}
cout<<"Impossible blood type:";
for(string I:ImPoBle)
{
cout<<I<<" ";
}
set<set<string>> S;
S.insert(PosBle);
S.insert(ImPoBle);
vector<vector<string>> P;
P.push_back(parents[0]);
P.push_back(parents[1]);
map<vector<vector<string>>,set<set<string>>> MAX;//
/* map mapStudent;
mapStudent.insert(pair(1, "student_one"));*/
MAX.insert(pair<vector<vector<string>>,set<set<string>>>(P, S));
}
map,set,vector,
,
,