1664: 串-简单串匹配
金币值:2
定数:6
时间限制:1.000 s
内存限制:128 M
正确:15
提交:31
正确率:48.39% 命题人:
题目描述
分别输入字符串S(主串)和字符串T(子串),补充下列程序输出T在S中第pos个字符之后的位置(1≤pos≤strlen(S))。
#include <stdio.h> #include <string.h> int Index(char s[], char t[], int pos);/* 返回子串T在主串S中第pos个字符之后的位置。若不存在,则函数返回值为0。 */ int main(void) { char s[81],t[81]; int i,pos; scanf("%s",s); scanf("%s",t); scanf("%d",&pos); i=Index(s,t,pos); printf("%d",i); return 0; } /*以下为你的代码*/
输入格式
第一行输入一个字符串S(主串),第二行输入一个字符串T(子串),第三行输入一个整型数值pos(1≤pos≤strlen(S))
输出格式
子串在主串第pos个字符之后的位置,如果子串不在主串中,输出0。
输入样例 复制
qazazazaz
zaz
4
输出样例 复制
5
提示
/*注意:以下提示代码为BF算法,也可以使用其他匹配算法。*/ int Index(char s[], char t[], int pos) { int i,j; i=pos; j=0; while(i<=strlen(s)-1 && j<=strlen(t)-1) { if(s[i]==t[j]) { } else { // 注意本处代码的推导过程 } } if(j==strlen(t)) { // 注意本处代码的推导过程 } else { } }