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

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

2016-06-19 15:24 417 查看
点击打开题目链接

#include <bits/stdc++.h>
#define N 1000010
using namespace std;

char _string1
, _string2
;
void cmp(char *str1, char *str2);

int main()
{

while(gets(_string1))
{
gets(_string2);
cmp(_string1, _string2);
}
return 0;
}

void cmp(char *str1, char *str2)
{
int lenth1 = strlen(str1), lenth2 = strlen(str2);
int i = 0, j = 0;
while(i < lenth1 && j < lenth2)
{
if(str1[i+j] == str2[j])
{
j++;
}
else
{
i ++;
j = 0;
}
}
if(str2[j] == '\0')
{
cout << "YES" << endl;
}
else
{
cout << "NO" << endl;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: