-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind.cpp
89 lines (84 loc) · 1.81 KB
/
find.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int to_find;
void preKMP(string pattern, int f[])
{
int m = pattern.length(), k;
f[0] = -1;
for (int i = 1; i < m; i++)
{
k = f[i - 1];
while (k >= 0)
{
if (pattern[k] == pattern[i - 1])
break;
else
k = f[k];
}
f[i] = k + 1;
}
}
//check whether target string contains pattern
bool KMP(string pattern, string target)
{
int m = pattern.length();
int n = target.length();
int f[m];
preKMP(pattern, f);
int i = 0;
int k = 0;
while (i < n)
{
if (k == -1)
{
i++;
k = 0;
}
else if (target[i] == pattern[k])
{
i++;
k++;
if (k == m){
to_find = i-k;
return 1;
}
}
else
k = f[k];
}
return 0;
}
int main(){
ifstream file("test.html");
string text;
cout<<"Enter the number of friends you want to see the name of"<<endl;
int n;
cin>>n;
string s = ",list:[";
int t;
string id;
vector<string> v;
while(getline(file,text,'\n')){
if(KMP(s,text)){
t = to_find + 8;
while(v.size()<n){
id = "";
while(text[t]!='-'){
id = id + text[t];
t++;
}
if(find(v.begin(),v.end(),id)==v.end()){
v.push_back(id);
}
t = t+ 5;
}
break;
}
}
for(int j=0;j<v.size();j++){
cout<<v[j]<<endl;
s = "firefox -new-tab http://www.facebook.com/"+v[j];
system(s.c_str());
}
}