?? 3-3-2.c
字號:
/*中國系統(tǒng)分析員顧問團(tuán),http://www.csai.cn*/
/*程序員下午考試指南書籍源碼*/
#include <stdio.h>
int strlen(char *s){
char * t = s;
while (*t++);
return t-s-1;
}
int commstr(char *str1,char *str2, int *sublen){
char *s1,*s2;
int count = 0, len1, len2 , k, j, i, p;
len1 = strlen(str1);
len2 = strlen(str2);
if (len1 > len2){
s1 = str1; s2 = str2;
}
else {
len2 = len1; s1 = str2; s2 = str1;
}
for(j = len2; j > 0; j--) { /* 從可能最長子串開始尋找 */
for(k = 0; k + j <= len2; k++){ /* k 為子串 S2 的開始位置 */
for( i = 0; s1[i + j - 1] != '\0'; i++){ /* i 為子串 s1 的開始位置 */
/* s1 的子串與 S2 的子串比較 */
for (p = 0; p < j && s1[i+p] == s2[k+p]; p++);
if (p == j ) { /* 如果兩子串相同 */
for (p = 0; p < j ; p++) /* 輸出子串 */
printf("%c", s2[k + p]);
printf("\n");
count++; /* 計數(shù)增 */
}
}
}
if (count > 0 ) break;
}
*sublen = (count > 0) ? j : 0 ;
return count;
}
main()
{
char a1[]={'a','b','c','a','d','\0'},a2[]={'a','c','c','a','b','c','\0'};
int c=0;
commstr(a1,a2,&c);
printf("Sublen=%d",c);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -