验证子串
来源:互联网 发布:冰锐和锐澳的区别 知乎 编辑:程序博客网 时间:2024/05/22 05:01
验证子串
时间限制: 1000 ms 内存限制: 65536 KB
提交数: 382 通过数: 196
【题目描述】
输入两个字符串,验证其中一个串是否为另一个串的子串。
【输入】
输入两个字符串, 每个字符串占一行,长度不超过200且不含空格。
【输出】
若第一个串s1是第二个串s2的子串,则输出(s1) is substring of (s2)
否则,若第二个串s2是第一个串s1的子串,输出(s2) is substring of (s1)
否则,输出 No substring。
【输入样例】
abcdddncabca
【输出样例】
abc is substring of dddncabca
【来源】
No
【代码】
#include<iostream>#include<cstdio>#include<cmath>#include<cstring>#include<iomanip>using namespace std;int main(){char s1[200],s2[200];//按照题目要求定义字符数组char tem1[200],tem2[200];int i,j;gets(s1);gets(s2);if(strlen(s1)<=strlen(s2))//保证tem2数组比tem1数组要长{strcpy(tem1,s1);strcpy(tem2,s2);}else {strcpy(tem1,s2);strcpy(tem2,s1);}for(i=0;i<strlen(tem2);i++)//同时遍历tem2数组和tem1数组{if(tem1[0]==tem2[i]){for(j=0;j<strlen(tem1);j++){if(tem1[j]==tem2[i+j]) {if(j==strlen(tem1)-1) {printf("%s is substring of %s",tem1,tem2);return 0;}}else break;}}}cout<<"No substring";return 0;}
【说明】
1.vc6.0运行成功,提交通过。阅读全文
0 0
- 验证子串
- 18:验证子串
- 验证子串
- 18.验证子串
- noi-8176-验证子串
- 字符串练习18_验证子串
- 设计一个字符串子串删除函数 将结果子串指针返回 用主程序验证
- 密码验证合格程序(判断字符串是否有重复子串)
- 子串
- 子串
- 子串
- 子串
- 子串
- 子串
- 子串
- 子串
- 子串
- 子串
- 决策树(ID3)c++实现(未剪枝)
- 总是这么奇怪
- 科普LLVM中MSP430如何lower移位指令
- ORM与JPA及Hibernate三者之间的关系
- 数据结构 队列的实现
- 验证子串
- ResourceManager(一)—— ArchiveManager
- 万商联店铺会员管理系统v3.8破解带收银系统
- LinuxStudyNote(42)-RPM包安装、更新、卸载命令、包名和包全名的概念
- [线性规划 费用流]Codeforces Gym101190D.Delight for a cat
- Java I/O Reader及其子类源码解析
- VS2013如何添加LIb库及头文件的步骤
- python开发环境的搭建
- SpringMVC 报org.springframework.beans.factory.NoSuchBeanDefinitionException