实现在一个母字符串中找到第一个子字符串的位置。

#include <stdio.h>
#include <string.h>

#define _IRON_TRUE 1
#define _IRON_FALSE 0

typedef int BOOL;

int strStr(char* s1, char* s2)
{
        ;
        int l1 = strlen(s1);
        int l2 = strlen(s2);

        ) ;

        ;

        , j = ;
        ; i <= (l1-l2); i++)
        {
                BOOL successFlag = _IRON_FALSE;
                ; j < l2; j++)
                {
                        if(*(s1+i+j) != *(s2+j))
                        {
                                successFlag = _IRON_FALSE;
                                break;
                        }

                        successFlag = _IRON_TRUE;
                }

                if(successFlag) return i;
        }

        ;
}

int main(int argc, char* argv[])
{
        )
        {
                printf("please input two str param, the first is haystack and the second is needle\n");
        }
        ];
        ];

        int i = strStr(s1,s2);
        printf("%d",i);
}

c语言 Implement strStr()【Leetcode】的更多相关文章

  1. Implement strStr() [LeetCode]

    Implement strStr(). Returns a pointer to the first occurrence of needle in haystack, or null if need ...

  2. Implement strStr() leetcode java

    题目: Implement strStr(). Returns a pointer to the first occurrence of needle in haystack, or null if ...

  3. [LeetCode] Implement strStr() 实现strStr()函数

    Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...

  4. [Leetcode] implement strStr() (C++)

    Github leetcode 我的解题仓库   https://github.com/interviewcoder/leetcode 题目: Implement strStr(). Returns ...

  5. [Leetcode][Python]28: Implement strStr()

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 28: Implement strStr()https://oj.leetco ...

  6. 【一天一道LeetCode】#28. Implement strStr()

    一天一道LeetCode系列 (一)题目 Implement strStr(). Returns the index of the first occurrence of needle in hays ...

  7. LeetCode专题-Python实现之第28题: Implement strStr()

    导航页-LeetCode专题-Python实现 相关代码已经上传到github:https://github.com/exploitht/leetcode-python 文中代码为了不动官网提供的初始 ...

  8. 【LeetCode】Implement strStr()(实现strStr())

    这道题是LeetCode里的第28道题. 题目描述: 实现 strStr() 函数. 给定一个 haystack 字符串和一个 needle 字符串,在 haystack 字符串中找出 needle ...

  9. LeetCode(28)题解:Implement strStr()

    https://leetcode.com/problems/implement-strstr/ 题目: Implement strStr(). Returns the index of the fir ...

随机推荐

  1. 通过IDEA及hadoop平台实现k-means聚类算法

    由于实验室任务方向变更,本文不再更新~ 有段时间没有操作过,发现自己忘记一些步骤了,这篇文章会记录相关步骤,并随时进行补充修改. 1 基础步骤,即相关环境部署及数据准备 数据文件类型为.csv文件,e ...

  2. 洛谷 P1003 铺地毯

    嗯.... 一道比较水的模拟题.. 刚拿到题的时候被它的数据范围吓到了,二维数组不可能开那么大啊,可是一边做发现测试数据太水 ... 先看一下题吧... 题目描述 为了准备一个独特的颁奖典礼,组织者在 ...

  3. CSS(十三).高度如何铺满全屏

    该需求来源一次面试题. IE6不认识!important声明,IE7.IE8.Firefox.Chrome等浏览器认识:而在怪异模式中,IE6/7/8都不认识!important声明,这只是区别的一种 ...

  4. Linq 查询内建议不要使用运算语句!

    比如list有2个值,当你运行完上述代码后,你会发现,你的ls中的Num没有按你预期的那样从0开始,导致这个问题的原因是:在你查询完毕后,执行的Count()方法,会导致查询语句中Num=num++再 ...

  5. Go语言基础之19--web编程基础

    一.web编程基础 1.1 web工作方式 1.2 HTTP协议详解 a.http 请求包体 GET /domains/example/ HTTP/1.1 //请求行: 请求方法 请求URI HTTP ...

  6. Go语言基础之6--map(字典)数据类型

    一.map数据类型 1.1 声明和定义 map类型是一个key-value的数据结构,又叫字典.(map也是可以扩容的,内部自动扩容) 声明: var map1 map[keytype]valuety ...

  7. apply,call,bind

    /*apply和call都是为了改变某个函数运行时的上下文而存在的(就是为了改变函数内部this的指向): 如果使用apply或call方法,那么this指向他们的第一个参数,apply的第二个参数是 ...

  8. VUE验证器哪家强? VeeValidate absolutely!

    VUE验证器哪家强? VeeValidate absolutely! vee-validate表单验证用法 github地址:https://github.com/baianat/vee-valida ...

  9. Robot Framework 的安装和配置

    Robot Framework 的安装和配置 在使用 RF(Rebot framework)的时候需要 Python 或 Jython 环境,具体可根据自己的需求来确定.本文以在有 Python 的环 ...

  10. accept 和 connect API深入 重点accept阻塞和非阻塞问题学习

    https://www.cnblogs.com/zhangkele/p/10284234.html