题目(材料题)
1 #include <iostream>
2 #include <string>
3 #include <vector>
4
5 using namespace std;
6
7 int f(const string & s, const string & t)
8 {
9 int n = s.length(), m = t.length();
10
11 vector<int> shift(128, m + 1);
12
13 int i, j;
14
15 for (j = 0; j < m; j++)
16 shift[t[j]] = m - j;
17
18 for (i = 0; i <= n - m; i += shift[s[i + m]]) {
19 j = 0;
20 while (j < m && s[i + j] == t[j]) j++;
21 if (j == m) return i;
22
}
23
24 return -1;
25 }
26
27 int main()
28 {
29 string a, b;
30 cin >> a >> b;
31 cout << f(a, b) << endl;
32 return 0;
33 }
假设输入字符串由 ASCII 可见字符组成,完成下面的判断题和单选题:
||

关注我们