-
Notifications
You must be signed in to change notification settings - Fork 0
/
Implement strStr().cpp
47 lines (44 loc) · 1.05 KB
/
Implement strStr().cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include<iostream>
#include<string>
using namespace std;
int strStr(string haystack, string needle) {
int len=haystack.size();
int lenn=needle.size();
int pointh=0,pointn=0;
if(lenn==0)
return 0;
for (int i=0;i<len;i++)
{
if (i+lenn-1<len)
{
pointh=i;
if (haystack[pointh]==needle[pointn])
{
int flag=0;
for (int j=1;j<lenn;j++)
{
if (haystack[++pointh]==needle[j])
continue;
else
{
flag=1;
break;
}
}
if (flag==0)
{
return i;
}
}
}
}
return -1;
}
int main()
{
string a="";
string b="";
int c=strStr(a,b);
cout<<c;
return 0;
}