预览加载中,请您耐心等待几秒...
1/10
2/10
3/10
4/10
5/10
6/10
7/10
8/10
9/10
10/10

亲,该文档总共22页,到这已经超出免费预览范围,如果喜欢就直接下载吧~

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

大概一年前写代码实现了这个算法,今天有人问我要,在这里贴出来好了。具体算法思路我也忘了,但是代码应该还算清晰。只需要事先了解下STL。viewplaincopytoclipboardprint?/*测试数据21/10X1X2X3X4X5X6X7X8X9yU1c6yEmhhammU2c6nEmmhmammU3c6nEmhhmammU4c4yEmhhmalhU5c6nEmmmmammU6c6nBmmmaheloU7c6nEmmhmaheloU8s4nBsmhlomalhU9c4nBsmhlomammU10c4nBsmhmammU11s4nEsmhlomalhU12s4nEmmmmamhU13c4nBmmmmammU14s4yEsmhhmamhU15s4nBsmmlomamhU16c4yEmmhmammU17c6nEmmhammU18c4nEmmhammU19s4nEsmhmmamhU20c4nEsmhmmamhU21c4nBsmhmmamm*/#include<iostream>#include<fstream>#include<vector>#include<set>#include<string>#include<iomanip>usingnamespacestd;#defineDATA_FILE_NAME"../data.txt"#defineDEF_ATTR_CNT10#defineDEF_OBJ_CNT21intg_attr_cnt=0;intg_obj_cnt=0;classobject;vector<string>g_attr_set;vector<bool>g_mask;vector<object*>g_obj_set;vector<string>g_core_set;vector<string>g_b_set;vector<vector<object*>*>g_ind_c_set;vector<vector<object*>*>g_ind_b_set;voidclr_mask(conststring&attr){inti=0;for(i=0;i<g_attr_cnt;i++){if(attr==g_attr_set[i])g_mask[i]=false;elseg_mask[i]=true;}}voidset_mask(){inti=0;for(i=0;i<g_attr_cnt;i++){g_mask[i]=true;}}voidset_mask_set(vector<string>&str_set){inti=0,j=0;boolfound=false;for(i=0;i<g_attr_cnt;i++){found=false;for(j=0;j<str_set.size();j++){if(g_attr_set[i]==str_set[j]){found=true;break;}}if(found)g_mask[i]=true;elseg_mask[i]=false;}}classobject{public:vector<string>attr_val;stringobj_name;public:object(conststring&name):obj_name(name){attr_val.reserve(DEF_ATTR_CNT);}~object(){}booloperator==(constobject&r_obj)const{boolres=true;inti=0;for(i=0;i<g_attr_cnt;i++){if(g_mask[i])res&=(attr_val[i]==r_obj.attr_val[i]);if(false==res)break;}returnres;}};voidread_data(){stringstrTmp;ifstreamdata_in(DATA_FILE_NAME,ifstream::in);inti=0,j=0;object*p_obj=NULL;g_attr_set.reserve(DEF_ATTR_CNT);g_mask.reserve(DEF_ATTR_CNT);g_obj_set.reserve(DEF_OBJ_CNT);//readobjectcount,andattrcountdata_in>>strTmp;g_obj_cnt=atoi(strTmp.substr(0,strTmp.find("/")).c_str());g_attr_cnt=atoi(strTmp.substr(strTmp.find("/")+1,strTmp.length()).c_str());for(i=0;i<g_attr_cnt;i++){data_in>>strTmp