验证子串是一道较为经典的题目,具有一些难度。但是,并不算难。题目如下:
输入两个字符串,验证其中一个串是否为另一个串的子串:
#include<bits/stdc++.h>
using namespace std;
int main(){
char a[100],b[100];
cin>>a>>b;
if(strstr(b,a)) cout<<a<<" is substring of "<<b;
else if(strstr(a,b)) cout<<b<<" is substring of "<<a;
else cout<<"No substring";
}
此方法为验证子串较方便的方法实现的,希望能帮助到你。