字典序 我的解法
string tofind="ab";char* mystring=NULL;
int c=0;
int i;
int count=0;
#define LEN 13
hash_map<string,int> myhash;
ofstream out1("log1.txt");
time_t begin=time(NULL);
while(c++ < LEN)
{
mystring=new char;
for(i=0;i<c+1;i++)
mystring='a'+i;
mystring=0;
while(true)
{
myhash=++count;
mystring++;
if(mystring > 'z')
{
bool canfind=false;
for(i=c-2;i>=0;i--)
{
if(mystring < 'z'-c+1+i)
{
canfind=true;
break;
}
}
if(!canfind)
break;
else
{
mystring++;
while(++i<c)
{
mystring=mystring+1;
}
}
}
}
delete []mystring;
}
hash_map<string,int>::iterator itor=myhash.find(tofind);
cout<<(*itor).second<<endl<<"用时:"<<time(NULL)-begin;
//LEN=6时 debug 601s release 1s 单词数20W+ LEN=10时 release 16s
贴代码不带TAB……
页:
[1]