【题目描述】
输入两个字符串,验证其中一个串是否为另一个串的子串。
【输入】
输入两个字符串, 每个字符串占一行,长度不超过200且不含空格。
【输出】
若第一个串s1是第二个串s2的子串,则输出(s1) is substring of (s2)
否则,若第二个串s2是第一个串s1的子串,输出(s2) is substring of (s1)
否则,输出 No substring。
【输入样例】
abc dddncabca
【输出样例】
abc is substring of dddncabca
这题是字符串的字串问题strstr()注意是在string.h中
其实要知道字符串位移包含的问题
#include<iostream>
#include<string>
#include<iostream>
#include<string>
//#include<bits/stdc++.h>
#include<cctype>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
string s1,s2;
getline(cin,s1);
getline(cin,s2);
string t;
if(s1.size()<s2.size())
{
t=s1;
s1=s2;
s2=t;
}
//cout<<strstr(s1.c_str(),s2.c_str())<<endl;
if(strstr(s1.c_str(),s2.c_str()))
{
cout<<s2<<" is substring of "<<s1<<endl;
}
else
cout<<"No substring"<<endl;
return 0;
}