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 | #include <iostream> #include <string> #include <vector> using namespace std; int f(const string &s, const string &t) { int n = s.length(), m = t.length(); vector<int> shift(128, m + 1); int i, j; for (j = 0; j < m; j++) shift[t[j]] = m - j; for (i =0; i<= n - m; i += shift[s[i + m]]){ j =0; while(j < m && s[i +j] == t[j]) j++; if (j == m) return i; } return -1; } int main() { string a ,b; cin >> a >> b; cout << f(a, b) << endl; return 0; } |
假设输入字符串由 ASCII 可见字符组成,完成下面的判断题和单选题:
0 of 6 Questions completed
Questions:
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
0 of 6 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
1、当输入为“abcde fg”时,输出为-1。
2、当输入为“abbababbbab abab”时,输出为 4。
3、当输入为“GoodLuckCsp2022 22”时,第 20 行的“j++”语句执行次数为 2。
4、该算法最坏情况下的时间复杂度为( )。
5、f(a, b) 与下列( )语句的功能最类似。
6、当输入为“baaabaaabaaabaaaa aaaa”,第 20 行的“j++”语句执行次数为 ( )。