Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <cstring>
- #include <algorithm>
- #include <vector>
- using namespace std;
- ifstream in("subsecvente.in");
- ofstream out("subsecvente.out");
- int N;
- vector<string> Elemente;
- bool lenSort(string a, string b)
- {
- return a.length() < b.length();
- }
- int main()
- {
- in >> N;
- for (int i = 0; i < N; i++)
- {
- string temp;
- in >> temp;
- Elemente.push_back(temp);
- }
- sort(Elemente.begin(), Elemente.end(), lenSort);
- string prim = Elemente.front();
- int prim_len = (int)prim.length();
- int max = 1;
- bool ok = true;
- string sub;
- for (int start = 0; start < prim_len - 2; start++)
- for (int end = 2; end <= min(prim_len - start, 60) + 2; end++)
- {
- sub = prim.substr(start, end);
- ok = true;
- for (int n = 1; n < N; n++)
- {
- //cout << start << "\t" << end << "\t" << Elemente[n] << "\t" << sub << "\t" << (Elemente[n].find(sub) == string::npos) << endl;
- if (Elemente[n].find(sub) == string::npos)
- ok = false;
- }
- if (ok)
- {
- if (sub.length() > max)
- max = sub.length();
- }
- else break;
- }
- out << max;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement