zoukankan      html  css  js  c++  java
  • wikioi 1204 寻找子串位置

    /*========================================================================
    1204 寻找子串位置
    题目描述 Description
        给出字符串a和字符串b,保证b是a的一个子串,请你输出b在a中第一次出现的位置。
    输入描述 Input Description
        仅一行包含两个字符串a和b
    输出描述 Output Description
        仅一行一个整数
    样例输入 Sample Input
        abcd bc
    样例输出 Sample Output
        2
    数据范围及提示 Data Size & Hint
        字符串的长度均不超过100
        Pascal用户请注意:两个字符串之间可能包含多个空格
    ==========================================================================*/
    #include<stdio.h>
    #include<string.h>
    int main()
    {
        char a[105],b[105];
        int i,lenA,lenB,n,j,k;
        int f;
        char *res;
        freopen("6.in","r",stdin);
        scanf("%s%s",a,b);
        /*lenA=strlen(a);
        lenB=strlen(b);
        n=lenA-lenB;
        for(i=0;i<=n;i++)
        {
            f=1;
            for(j=i,k=0;k<lenB;j++,k++)
            {
                if(a[j]!=b[k])
                {
                    f=0;
                    break;
                }
            }
            if(f)
            {
                printf("%d
    ",i+1);
                break;
            }
        }*/
        res=strstr(a,b);
        printf("%d
    ",res-a+1);
        return 0;
    }
  • 相关阅读:
    php 延迟静态绑定: static关键字
    python分片
    用逗号分隔数字,神奇
    ubuntu 屏幕截图
    js 获取随机数
    netty : NioEventLoopGroup 源码分析
    LinkedList 源码分析
    面向对象
    JS
    网页
  • 原文地址:https://www.cnblogs.com/huashanqingzhu/p/3456862.html
Copyright © 2011-2022 走看看