Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- string str1, str2;
- cin >> str1 >> str2;
- if (str1 == str2)
- {
- cout << str1;
- return 0;
- }
- int N,N2;
- if (str1.length() > str2.length())
- {
- N = str2.length();
- swap(str1, str2);
- }
- else N = str1.length();
- N2 = str2.length();
- int maxCount = 0, ind1 = 0, ind2 = 0, start = 0, finish = 0;
- while (ind1 != N - 1)
- {
- if (maxCount == N - 1) break;
- if (str1[ind1] == str2[ind2])
- {
- int tmpStart = ind1, tmp1 = ind1 + 1, tmp2 = ind2 + 1, count = 1, barr = ind1, tmpFinish = ind1;
- while (barr != N - 1)
- {
- if (str1[tmp1] == str2[tmp2])
- {
- count++;
- tmpFinish = tmp1;
- tmp1++;
- tmp2++;
- barr++;
- }
- else
- {
- if (count > maxCount)
- {
- maxCount = count;
- start = tmpStart;
- finish = tmpFinish;
- }
- count = 0;
- ++ind2;
- break;
- }
- if (count > maxCount)
- {
- maxCount = count;
- start = tmpStart;
- finish = tmpFinish;
- }
- if (barr == N - 1) ++ind2;
- }
- }
- else ++ind2;
- if (ind2 == N2)
- {
- ind2 = 0;
- ++ind1;
- }
- }
- /*if (maxCount == 1) cout << str1[start];
- else {
- do
- {
- cout << str1[start];
- start++;
- maxCount--;
- } while (start <= finish);
- }*/
- if (maxCount != 1)
- {
- do
- {
- cout << str1[start];
- start++;
- } while (start <= finish);
- }
- else cout << str1[start];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement