#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;//特征映射表
map<int,string> tables ={{1,"grease"},{2,"crinte"},{3,"feather"},{4,"can fly"},{5,"oviparous"},{6,"crawls"},{7,"canine"},{8,"stare ahead"},{9,"eating-meat"},{10,"hooves"},{11,"ruminant"},{12,"filemot"},{13,"black stripes"},{14,"black scatters"},{15,"long legs"},{16,"long neck"},{17,"dark scatters"},{18,"white"},{19,"cant fly"},{20,"black and white"},{21,"can swim"},{22,"be good at flying"},{23,"good coping with wind and waves"},{24,"mammal"},{25,"bird"},{26,"flesh-eater"},{27,"ungulate"},{28,"artiodactyl"},{29,"tiger"},{30,"leopard"},{31,"giraffe"},{32,"zebra"},{33,"ostrich"},{34,"penguin"},{35,"salangane"}};//推理映射表
map<vector<int>,int> classific ={{{1},24},//1{{2},24},{{3},25},{{4,5},25},{{6,7,8,24},26},//5{{9,24},26},{{10,24},27},{{11,27},28},{{12,13,24},29},{{12,14,24},30},//10{{12,15,16,17,27},31},{{13,18,27},32},{{15,16,19,25},33},{{19,20,21,25},34},{{22,23,25},35}//15};//主程序
int main(){
int i,j,a,b,c;
int num;
vector<int> fact,temp;
int flag=1;while(flag==1){
cout<<"input the features ad following:"<<endl;//打印选项单
map<int,string>::iterator iter;
iter = tables.begin();while(iter->first <24){
cout<< iter->first <<"."<< iter->second<<"\t";if(iter->first%5==0)
cout<<endl;
iter ++;}
cout<<endl;//输入信息
cout<<"number of features:"<<endl;
cin>>num;
cout<<"input the features in order:"<<endl;for(i=0;i<num;i++){
cin>>a;
fact.push_back(a);}sort(fact.begin(),fact.end());//实现推理过程
map<vector<int>,int>::iterator vec_iter;
vector<int> insec,tmp_sec;
vec_iter = classific.begin();
i=0;while(vec_iter != classific.end()){
i ++;//按顺序判断映射表key是否包含于factset_intersection(vec_iter->first.begin(),vec_iter->first.end(),fact.begin(),fact.end(),back_inserter(insec));set_difference(vec_iter->first.begin(),vec_iter->first.end(),insec.begin(),insec.end(),inserter(tmp_sec,tmp_sec.begin()));if(tmp_sec.size()==0){//包含,则取fact和key的差集,并重新赋值给fact
insec.clear();set_difference(fact.begin(),fact.end(),vec_iter->first.begin(),vec_iter->first.end(),inserter(insec,insec.begin()));
fact.assign(insec.begin(),insec.end());//加入新结论
fact.push_back(vec_iter->second);
cout<<"rule "<<i<<" ,add "<<tables[vec_iter->second]<<" to fact"<<endl;}
tmp_sec.clear();
insec.clear();
vec_iter ++;}//判断是否得出结论
int res = fact.back();if(res<29)
cout<<"cant infer any result according to information you give"<<endl;else
cout<<"the animal may be "<<tables[res]<<endl;
cout<<"input number 1 if you want continue, or any other key to quit:"<<endl;
cin>>flag;}return1;}