我是靠谱客的博主 调皮小刺猬,这篇文章主要介绍1.7编程基础之字符串--18:验证子串,现在分享给大家,希望可以做个参考。

18:验证子串

原地址

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

输入
输入两个字符串, 每个字符串占一行,长度不超过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 <stdio.h>
#include <iostream>
#include <stack>
#include <string.h>
#include <queue>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <string>
#include <cstdio>
using namespace std;
int main() {
char s1[201],s2[201];
gets(s1);
gets(s2);
if(strlen(s1)>=strlen(s2)){
if(strstr(s1,s2)!=NULL) cout<<s2<<" is substring of "<<s1<<endl;
else cout<<"No substring"<<endl;
}//小心不要落下空格
else{
if(strstr(s2,s1)!=NULL) cout<<s1 <<" is substring of "<< s2<<endl;
else cout<<"No substring"<<endl;
}
return 0;
}

最后

以上就是调皮小刺猬最近收集整理的关于1.7编程基础之字符串--18:验证子串的全部内容,更多相关1内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(129)

评论列表共有 0 条评论

立即
投稿
返回
顶部