Advertisement
Alex_tz307

Subsecventa Comuna de Lungime Maxima - Matrice

Sep 12th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. ifstream fin ("sclm.in");
  6. ofstream fout ("sclm.out");
  7.  
  8. char s[1026], t[1026];
  9. int N, M, a[1026][1026], mx, in1, in2;
  10.  
  11. int main() {
  12.   fin >> N >> M >> (s + 1) >> (t + 1);
  13.   for (int i = 1; i <= N; i ++)
  14.   for (int j = 1; j <= M; j ++)
  15.     if (s[i] != t[j])
  16.       a[i][j] = 0;
  17.     else {
  18.         a[i][j] = a[i - 1][j - 1] + 1;
  19.         if (a[i][j] > mx) {
  20.           mx = a[i][j];
  21.           in1 = i;
  22.           in2 = j;
  23.         }
  24.     }
  25.   fout << mx << ' ' << in1 - mx + 1 << ' ' << in2 - mx + 1 << '\n';
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement