Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- using namespace std;
- string find_str_from2(string &s1, string &s2) {
- int i = 0;
- int j = 0;
- int flag = 0;
- int index = -1;
- while (i < s1.length() && j < s2.length()) {
- if (s1[i] == s2[j]){
- if (flag == 0) {
- flag = 1;
- index = i;
- }
- else flag++;
- i++;
- j++;
- }
- else {
- if (flag != 0) {
- j = 0;
- index = -1;
- flag = 0;
- }
- i++;
- }
- }
- if (index == -1) return s1 + s2;
- string str = "";
- for (int k = 0; k < index; k++) {
- str += s1[k];
- }
- for (int k = 0; k < s1.length() + s2.length() - flag - index; k++) {
- str += s2[k];
- }
- return str;
- }
- int find_str_from3(string &s1, string &s2, string &s3){
- string str1 = find_str_from2(s1, s2);
- string str2 = find_str_from2(str1, s3);
- return str2.length();
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- string s1, s2, s3;
- cin >> s1 >> s2 >> s3;
- if (s1 == s2 && s2 == s3) {
- cout << s1.length();
- return 0;
- }
- if (s1 == s2) {
- string str = find_str_from2(s1, s3);
- cout << str.length();
- return 0;
- }
- if (s2 == s3) {
- string str = find_str_from2(s2, s1);
- cout << str.length();
- return 0;
- }
- if (s1 == s3) {
- string str = find_str_from2(s1, s2);
- cout << str.length();
- return 0;
- }
- int a = find_str_from3(s1, s2, s3);
- int b = find_str_from3(s1, s3, s2);
- int c = find_str_from3(s2, s1, s3);
- int d = find_str_from3(s2, s3, s1);
- int e = find_str_from3(s3, s1, s2);
- int f = find_str_from3(s3, s2, s1);
- vector<int> vec = {a, b, c, d, e, f};
- min_element(vec.begin(), vec.end());
- cout << *min_element(vec.begin(), vec.end());
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement