⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 字符串查找.cpp

📁 包含冒泡排序算法函数模板和数据结构中的字符串查找例子及解线性方程组的3个典型算法加演示。
💻 CPP
字号:
//在主串s中查找字串t
#include<iostream.h>
int find(char s[],char t[]);
const int MAXLINE=256;
int main()
{
	char source[MAXLINE],target[MAXLINE];
	cout<<"Please input a string for searching:\n";
	cin.getline(source,MAXLINE);
	cout<<"Please input a string you want to find:\n";
	cin.getline(target,MAXLINE);
	int intPos=find(source,target);
	if(intPos>=0)
		cout<<"Finding it,The target string is at index "
		    <<intPos<<"of the source string\n";
	else
		cout<<"Not finding it\n";
	return 0;
}
int find(char s[],char t[])
{
	int i=0,j=0;
	for(i=0;s[i]!='\0';i++)
	{
		if(t[0]==s[i]){
			while(t[j]!='\0'&&s[i+j]!='\0'){
				j++;
				if(t[j]!=s[i+j])
					break;
			}
		}
		if(t[j]=='\0')
			return i;
	}
	return -1;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -