您的位置:首页 > 理论基础 > 数据结构算法

数据结构实验之串二:字符串匹配

2018-12-18 18:12 204 查看

p.s. c++中有个很好用的find函数,用与字符串查找,比KMP稍慢一点,具体用法如下

数据结构实验之串二:字符串匹配

Time Limit: 1000 ms Memory Limit: 65536 KiB

Problem Description

  给定两个字符串string1和string2,判断string2是否为string1的子串。

 

Input

 输入包含多组数据,每组测试数据包含两行,第一行代表string1,第二行代表string2,string1和string2中保证不出现空格。(string1和string2大小不超过100字符)

 

Output

 对于每组输入数据,若string2是string1的子串,则输出"YES",否则输出"NO"。

 

Sample Input

[code]abc
a
123456
45
abc
ddd

Sample Output

[code]YES
YES
NO

题目链接:

http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Contest/contestproblem/cid/2710/pid/2125

[code]#include <bits/stdc++.h>

using namespace std;

int main()
{
string s1,s2;
while(cin >> s1 >> s2)
{
int n=s1.find(s2);
if(n==-1)
cout << "NO" << endl;
else
cout << "YES" << endl;
}
return 0;
}

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: