输入两个字符串,验证其中一个串是否为另一个串的子串。
输入格式
输入两个字符串, 每个字符串占一行,长度不超过 200200 且不含空格。
输出格式
若第一个串 s_1s1 是第二个串 s_2s2 的子串,则输出"(s1) is substring of (s2)";
否则,若第二个串 s2是第一个串s1的子串,输出"(s2) is substring of (s1)";
否则,输出"No substring"。
Sample Inputabc
dddncabca
Sample Output
abc is substring of dddncabcaSponsor
借用到了c++中的find函数和c中的strstr函数
c++
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
string s1,s2;
int main()
{
cin>>s1>>s2;
if(s1.find(s2)!=s1.npos)
cout<<s2<<" is substring of "<<s1<<endl;
else if(s2.find(s1)!=s2.npos)
cout<<s1<<" is substring of "<<s2<<endl;
else
cout<<"No substring"<<endl;
return 0;
}