Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update 1.2:字符串是否包含问题.c #426

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion ebook/code/c/1.2:字符串是否包含问题.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void countSort(char * oldArr, char * newArr)
pos = count[*(oldArr + i) - 'A'];
while (newArr[pos - 1] != 0)
{
pos++;
pos--;
}
newArr[pos - 1] = *(oldArr + i);
}
Expand Down Expand Up @@ -154,6 +154,7 @@ bool contain2(char * stra, char * strb)
int lena = strlen(tmpA);
int lenb = strlen(tmpB);
int i, j;
/*
for (i = 0, j = 0; j < lena && i < lenb; j++)
{
if (tmpA[j] == tmpB[i])
Expand All @@ -173,6 +174,24 @@ bool contain2(char * stra, char * strb)
{
return false;
}
*/
for(i = 0,j = 0;i < lena && j < lenb;){
if(tmpA[i] == tmpB[j]){
j++;
while(tmpA[i] == tmpB[i + 1]){
i++;
}
}else if(tmpA[i] > tmpB[j]){
return false;
}else{
i++;
}
}
if(j == lenb){
return TRUE;
}else{
return false;
}
}
//hash测试法
bool contain3(char * stra, char * strb)
Expand Down