//https://www.nowcoder.com/practice/98dc82c094e043ccb7e0570e5342dd1b?tpId=37&&tqId=21298&sourceUrl=https%3A%2F%2Fwww.nowcoder.com%2Fexam%2Foj #include <iostream> #include <string> using namespace std; int main() { string str1, str2; cin >> str1 >> str2; // while(getline(cin, str)) //? 字符串的多用例输入 ctrl+z输入中止 // cin >> str; int n = str1.size(); int m = str2.size(); int t = 0; int maxn = 0; // cout << n << m << endl; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { while ((str1[i + t] == str2[j + t]) && i + t < n && j + t < m) t++; if (t != 0) { maxn = max(maxn, t); t = 0; } } } cout << maxn; }