【题目描述】
输入两个字符串,验证其中一个串是否为另一个串的子串。

【输入】
输入两个字符串, 每个字符串占一行,长度不超过200且不含空格。

【输出】
若第一个串s1是第二个串s2的子串,则输出(s1) is substring of (s2)

否则,若第二个串s2是第一个串s1的子串,输出(s2) is substring of (s1)

否则,输出 No substring。

【输入样例】
abc
dddncabca
【输出样例】
abc is substring of dddncabca

#include<iostream>
#include<string>
#include<iostream>
#include<string>
#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;
    }
    if(strstr(s1.c_str(),s2.c_str())){
        cout<<s2<<" is substring of "<<s1<<endl;
    }
    else
        cout<<"No substring"<<endl;
	return 0;
}
Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐