Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cstring>
- #include <list>
- std::pair<bool, std::list<char>> func(std::list<char>& first, std::list<char>& second)
- {
- auto it1 = first.begin();
- auto it2 = second.begin();
- while (it1 != first.end() || it2 != second.end())
- {
- if (*it1 != *it2)
- {
- if (it1 == first.begin())
- return std::make_pair(false, std::list<char>());
- if (*it1 != *std::prev(it1))
- {
- if (*it2 != *std::prev(it2))
- return std::make_pair(false, std::list<char>());
- second.erase(it2);
- ++it1;
- }
- else
- {
- if (*it1 != *std::prev(it1))
- return std::make_pair(false, std::list<char>());
- first.erase(it1);
- ++it2;
- }
- }
- else ++it1, ++it2;
- }
- if (it1 == first.end() && it2 == second.end())
- return std::make_pair(true, first);
- else if (it1 == first.end())
- {
- while (it2 != second.end())
- {
- if (*it2 != *std::prev(it1))
- return std::make_pair(false, std::list<char>());
- else
- second.erase(it2);
- }
- return std::make_pair(true, first);
- }
- else
- {
- while (it1 != first.end())
- {
- if (*it1 != *std::prev(it2))
- return std::make_pair(false, std::list<char>());
- else
- first.erase(it1);
- }
- return std::make_pair(true, first);
- }
- }
- int main()
- {
- char input1[100], input2[100], input3[100];
- std::scanf("%s\n%s\n%s", input1, input2, input3);
- std::list<char> string1, string2, string3;
- std::move(input1, input1 + std::strlen(input1), std::back_inserter(string1));
- std::move(input2, input2 + std::strlen(input2), std::back_inserter(string2));
- std::move(input3, input3 + std::strlen(input3), std::back_inserter(string3));
- std::pair<bool, std::list<char>> res1 = func(string1, string2);
- if (!res1.first)
- std::puts("IMPOSSIBLE");
- else
- {
- std::pair<bool, std::list<char>> res2 = func(res1.second, string3);
- if (!res2.first)
- std::puts("IMPOSSIBLE");
- else
- for (char elem : res2.second)
- std::printf("%c", elem);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement