strstr函数字符串匹配问题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Let_life_stop/article/details/82525972

题目链接:http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/2772.html

AC代码:

#include<bits/stdc++.h>
using namespace std;
char s1[1000000],s2[1000000];
int main()
{
    while(~scanf("%s%s",s1,s2))
    {
        char  *temp=strstr(s1,s2);
        if(temp==NULL)
            printf("-1\n");
        else
            printf("%d\n",temp-s1+1);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/Let_life_stop/article/details/82525972