Description
给定两个字符串string1和string2,判断string2是否为string1的子串。
Input
输入包含多组数据,每组测试数据包含两行,第一行代表string1,第二行代表string2,string1和string2中保证不出现空格。
Output
对于每组输入数据,若string2是string1的子串,则输出"YES",否则输出"NO"。
Sample Input
abc a 123456 45 abc ddd
Sample Output
YES YES NO
函数原型:extern char *strstr(char *haystack, char *needle)
参数说明:haystack为一个源字符串的指针,needle为一个目的字符串的指针。 所在库名:#include <string.h> 函数功能:从字符串haystack中寻找needle第一次出现的位置,但是该函数不比较结束符NULL。 返回说明:返回指向第一次出现needle位置的指针,如果没找到则返回NULL。
#include<stdio.h> #include<algorithm> #include<string.h> #include<iostream> #define N 999 using namespace std; int main() { char str1[N],str2[N],str3[N]; while(cin>>str1>>str2) { if(strstr(str1,str2)) printf("YES\n"); else printf("NO\n"); } return 0; }