Cod sursa(job #2476974)
| Utilizator | Data | 19 octombrie 2019 13:25:52 | |
|---|---|---|---|
| Problema | Substr | Scor | 40 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.56 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("substr.in");
ofstream fout("substr.out");
int n, k, ans;
string s[30000], c;
string :: iterator it1, it2;
int main()
{
fin >> n >> k;
fin >> c;
for(int i = 0; i < n; i++)
s[i]=c.substr(i);
sort(s, s+n);
for(int i = 0; i <= n-k; i++)
{
int cnt = 0;
it1 = s[i].begin();
it2 = s[i+k-1].begin();
while(*it1 == *it2 && *it1 && *it2) cnt++, it1++, it2++;
ans = max(ans, cnt);
}
fout << ans;
return 0;
}
