题目:找到词典中某词的变位词 源自编程珠玑 程序是自己的想法和思路 与书一样纯属巧合
程序:不能运行 只有关键函数 和类
#include<cstring>
#include<vector>
using namespace std;
const char UNSET='0';
const char SET='1';
const string NEW="000000000000000000000000000";
const int GAP=32;
vector<string> id_map;
class sto_wor
{
private:
string wor;
string mea;
string id;
public:
sto_wor(){id=NEW;}
~sto_wor(){}
string get_wor(){return wor;}
string get_mea(){return mea;}
string get_id(){return id;}
void set_wor(const string& tem){wor=tem;}
void set_mea(const string& tem){mea=tem;}
void set_id();
bool operator==(sto_wor&);
friend void to_low(string&);
};
void sto_wor::set_id()
{
to_low(wor);
for(int i=0;i<wor.length();i++)
{
id[wor[i]-'a'+1]++;
}
id[0]=SET;
}
bool sto_wor::operator==(sto_wor& sec)
{
if(id[0]==UNSET)
set_id();
if(sec.id[0]==UNSET)
sec.set_id();
return id==sec.id;
}
void to_low(string& aim)
{
for(int i=0;i<aim.length();i++)
{
if(aim[i]<'Z')
aim[i]+=GAP;
}
}
void sea_wor(sto_wor& aim)
{
int low=0;
int hig=id_map.size();
while(low<=hig)
{
mid=(low+hig)/2;
if(aim.get_id()<id_map[mid])
hig=mid-1;
else if(aim.get_id()>id_map[mid])
low=mid+1;
else cout<<"something";
}
cout<<"something else";
}