第八周 專案5 計數的模式匹配

2021-07-06 04:35:31 字數 1176 閱讀 2657

*問題描述:採用順序結構儲存串,編寫乙個演算法計算指定子串在乙個字串中出現的次數,如果該子串不出現則為0。

*輸入描述:兩個字串

*程式輸出:子串出現的次數

*/**:

(1)標頭檔案 s.h

#ifndef sqstring_h_included

#define sqstring_h_included

#define maxsize 100             //最多的字元個數

typedef struct

sqstring;

void strassign(sqstring &s,char cstr);    //字串常量cstr賦給串s

void strcopy(sqstring &s,sqstring t);   //串t複製給串s

bool strequal(sqstring s,sqstring t); //判串相等

int strlength(sqstring s);  //求串長

sqstring concat(sqstring s,sqstring t);  //串連線

sqstring substr(sqstring s,int i,int j); //求子串

sqstring insstr(sqstring s1,int i,sqstring s2); //串插入

sqstring delstr(sqstring s,int i,int j) ;   //串刪去

sqstring repstr(sqstring s,int i,int j,sqstring t);     //串替換

void dispstr(sqstring s);   //輸出串

#endif // sqstring_h_included

(2)原始檔 s.cpp

#include

#include "s.h"

int str_count(sqstring s,sqstring t)

}return(count);

}void strassign(sqstring &s,char cstr) //s為引用型引數

void dispstr(sqstring s)

執行結果:

第八周 專案5計數的模式匹配

all right reserved.檔名稱 project5.cpp 作 者 商文軻 完成日期 2015年10月20日 版 本 號 v1.9 問題描述 採用順序結構儲存串,編寫乙個演算法計算指定子串在乙個字串中出現的次數,如果該子串不出現則為0 程式採用多組織結構,用到順序串演算法庫sqstrin...

第八周 專案5 計數的模式匹配

檔名稱 main.cpp 作者 王超 完成日期 2015年10月23日 問題描述 計數的模式匹配 include include sqstring.h int main include include include sqstring.h int str count sqstring s,sqstr...

第八周專案5計數的匹配模式

問題及描述 輸入描述 sqstring.h ifndef sqstring h included define sqstring h included define maxsize 100 最多的字元個數 typedef struct sqstring void strassign sqstring...