Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <algorithm>
- #include <vector>
- using namespace std;
- void solving(string x, string y, int lx, int ly){
- vector <string> res;
- vector <vector <int>> mark(lx, vector <int>(ly));
- int max = 0;
- for(int i = 0; i < lx; i++){
- for(int j = 0; j < ly; j++){
- if(x[i] != y[j]){
- mark[i][j] = 0;
- continue;
- }
- if(i == 0 || j == 0){
- mark[i][j] = 1;
- }else{
- mark[i][j] = mark[i - 1][j - 1] + 1;
- }
- if(mark[i][j] > max){
- max = mark[i][j];
- res.clear();
- res.push_back(x.substr(i + 1 - max, (i + 1) - (i + 1 - max)));
- }else if(mark[i][j] == max){
- res.push_back(x.substr(i + 1 - max, (i + 1) - (i + 1 - max)));
- }
- }
- }
- sort(res.begin(), res.end());
- cout << res[0] << endl;
- }
- string evolve(string temp){
- string a = temp;
- a.erase(remove_if(a.begin(), a.end(), [](char c){
- return c == ',' || c == '.' || c == '!' || c == '?';
- }), a.end());
- transform(a.begin(), a.end(), a.begin(), ::toupper);
- return a;
- }
- int main(){
- string x, y;
- cin >> x >> y;
- string X = evolve(x);
- string Y = evolve(y);
- int m = x.length();
- int n = y.length();
- solving(X, Y, m, n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement