zoukankan      html  css  js  c++  java
  • 串结构练习--字符串匹配

    串结构练习——字符串匹配

    Time Limit: 1000MS Memory limit: 65536K

    题目描述

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

    输入

     输入包含多组数据,每组测试数据包含两行,第一行代表string1,第二行代表string2,string1和string2中保证不出现空格。
     

    输出

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

    示例输入

    abc
    a
    123456
    45
    abc
    ddd

    示例输出

    YES
    YES
    NO
     
    #include<stdio.h>
    #include<string.h>
    int main()
    {
    	char str1[100], str2[100];
    	while(scanf("%s %s", str1, str2)!=EOF)
    	{
    		if(strstr(str1, str2)!=NULL)
    			printf("YES
    ");
    		else
    			printf("NO
    ");
    	}
    }
    

    strstr 为字符串匹配函数,如果字符串str2, 是字符串str1 的子串, 则strstr 返回值为非空, 否者返回值为NULL。

    每天训练发现我比别人做的好慢,但是理解的更深刻,如果一开始学一个新知识点就搜模板,那么这样的人是走不远的,毕业之后带走的只有思维,什么荣誉,奖杯都已经不重要了。
  • 相关阅读:
    指针
    Centos6.5 安装Vim7.4
    C++ Prime:指针和const
    C++ Prime:const的引用
    C++ Prime:函数
    C++ Prime:范围for语句
    python的oop概述
    脚本单独调用django模块
    xtrabackup备份之xbstream压缩
    MySQL8.0安装
  • 原文地址:https://www.cnblogs.com/6bing/p/3931317.html
Copyright © 2011-2022 走看看