浠婂ぉ鏈夋湅鍙嬫寚鍑烘潵紼嬪簭榪愯緇撴灉閿欒錛岃瘯浜?jiǎn)涓嬪Q屾灉鐒舵湁闂錛屽湪涓嬬彮閫斾腑閲嶆柊鏁寸悊浜?jiǎn)鎬濊礬錛屼慨鏀逛簡(jiǎn)浠g爜錛屾暣浣撴濊礬涓嶅彉錛屽氨鏄姞浜?jiǎn)鍑犺浠g爜锛屽鐞嗗瓧绗︿覆鐨勬渶鍚庨儴鍒嗐傛眰楠岃瘉緇撴灉銆?br />欏轟究闂笅錛屾庝箞鍙栨秷鏂囩珷琚瘎璁烘椂鏀跺埌緋葷粺閫氱煡鐨勯偖浠跺憿錛?br />
char*GetSubStr( const char*str )
{
int hash[256]; //hash璁板綍姣忎釜瀛楃鐨勫嚭鐜頒綅緗?/span>
int i;
for( i = 0;i<256;i++ )
hash[i]=-1;
int CurrentStart=0,MaxStart=0,MaxEnd=0,MaxLength =0,CurrentLength = 0,strLen = strlen(str);
for(i=0;i<strLen;i++)
{
if(CurrentStart>hash[str[i]]) //濡傛灉娌℃湁閲嶅
{
hash[str[i]]=i;
}
else
{
CurrentLength=i-CurrentStart; //褰撳墠闀垮害
if(CurrentLength>MaxEnd-MaxStart)//濡傛灉褰撳墠闀垮害鏈闀?/span>
{
MaxEnd=i;
MaxStart=CurrentStart;
}
CurrentStart=hash[str[i]]+1; //鏇存柊褰撳墠鏈闀跨殑璧風(fēng)偣
hash[str[i]]=i; //鏇存柊瀛楃鍑虹幇鐨勪綅緗?/span>
}
}
//澧炲姞鐨勪唬鐮?/span>
if( strLen - CurrentStart> CurrentLength)
{
MaxEnd = strLen;
MaxStart=CurrentStart;
}
//
MaxLength=MaxEnd-MaxStart;
char*reStr = new char[MaxLength+1];
reStr[MaxLength]=0;
memcpy( reStr,str+MaxStart,MaxLength );
return reStr;
}

]]>