#include <stdio.h>
#include <stdbool.h>
#include <string.h>
/*寻找子串出现的最后的位置*/
char *strrstr(const char *string, const char *ending){
char *pos, *last;
int len;
len = strlen(ending);
pos = strstr(string, ending); /*出现第一个位置*/
if(NULL == pos)
return NULL;
/*找到最后出现的位置*/
last = pos + len;
while(1){
pos = strstr(last, ending);
if(NULL == pos)
break;
last = pos + len;
}
return last - len;
}
bool solution(const char *string, const char *ending){
char *pos;
int len;
if(*ending == '\0') /*子串""是任何字符串的尾端*/
return true;
len = strlen(ending);
pos = strrstr(string, ending);
if(!pos || *(pos + len) != '\0') /*检测是否在尾端*/
return false;
return true;
}
int main(){
const char *s = "babbabbab";
const char *e = "bab";
if(!solution(s, e))
puts("no");
else
puts("yes");
return 0;
}