在字符串S中寻找最长的字符串x,条件是x存在于S中。即是如:abcabcdcd中的abc。
\#include "stdafx.h"\
int main()\
{\
char szStr[] = "abcabcdcd";\
\
int len = strlen( szStr );\
for( int curLen = len/2; curLen \> 0; curLen-- )\
for( int j = 0; j \< len - curLen - curLen; j++ )\
if( strncmp(szStr + j, szStr + curLen + j, curLen) == 0 )\
{\
szStr[curLen+j] = '\\0';\
cout \<\< szStr + j \<\< endl;\
\
return 0;\
}\
}