7-105 串的模式匹配 (25分)(strstr的应用 )

在这里插入图片描述
看网上题解大部分都是用的KMP,个人比较懒,看到这个题感觉依稀记得有一个函数可以用来找子串。
strstr(s,t)函数,在s串中找子串t,如果没找到返回false,如果找到就返回剩下部分。
正好和该题题意完美契合,事实证明掌握一些函数关键时刻有奇效,代码如下:

#include<bits/stdc++.h>
using namespace std;
char s[1000100],t[1000010];
int n;
int main()
{
	cin>>s;
	getchar();
	cin>>n;
	while(n--)
	{
		cin>>t;
		getchar();
		if(!strstr(s,t))	cout<<"Not Found"<<endl;
		else	cout<<strstr(s,t)<<endl;
	}
}
发布了180 篇原创文章 · 获赞 22 · 访问量 9016

猜你喜欢

转载自blog.csdn.net/qq_44622401/article/details/104263378
今日推荐