PTA 查詢子串 (字串 函式)

2021-09-11 08:44:00 字數 606 閱讀 5116

本題要求實現乙個字串查詢的簡單函式。

char *search( char *s, char *t );
函式search在字串s中查詢子串t,返回子串t在s中的首位址。若未找到,則返回null。

#include #define maxs 30

char *search(char *s, char *t);

void readstring( char s ); /* 裁判提供,細節不表 */

int main()

/* 你的**將被嵌在這裡 */

the c programming language

ram

the c programming language

bored

-1

**

char *search(char *s, char *t)

if (k >= tlen)

k = 0;

} return p;

}

字串 查詢子串

主要的思路就是,不斷的從母串 str1 中取出和子串長度相等的臨時子串 temp str,與子串 str2 進行比較。沒有找到子串,返回 1 成功找到子串,返回子串首字母在母串中的位置,該位置從 0 開始。include include char temp str 30 臨時子串 void read...

查詢 子字串查詢

子字串查詢 子字串查詢的常見方法 暴力破解 sunday和kmp。1 暴力查詢 暴力查詢就是用兩個指標i,j分別指向字串和子字串,如果指標指向的字元相等則兩指標右移 否則,指向字串的指標i回到本次匹配的下乙個位置,而指向匹配字串的指標j回到匹配字串的開頭。public int search stri...

Python 的字串類子串查詢函式

python 的字串類有個很好用的函式,可很方便的用於與查詢python字串型別物件子串相關的操作,具體的api如下 find s.find sub start end int return the lowest index in s where substring sub is found,suc...