Advertisement
paranid5

доделать

Sep 27th, 2020
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.98 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cstring>
  3. #include <list>
  4.  
  5. std::pair<bool, std::list<char>> func(std::list<char>& first, std::list<char>& second)
  6. {
  7.     auto it1 = first.begin();
  8.     auto it2 = second.begin();
  9.  
  10.     while (it1 != first.end() || it2 != second.end())
  11.     {
  12.         if (*it1 != *it2)
  13.         {
  14.             if (it1 == first.begin())
  15.                 return std::make_pair(false, std::list<char>());
  16.  
  17.             if (*it1 != *std::prev(it1))
  18.             {
  19.                 if (*it2 != *std::prev(it2))
  20.                     return std::make_pair(false, std::list<char>());
  21.  
  22.                 second.erase(it2);
  23.                 ++it1;
  24.             }
  25.  
  26.             else
  27.             {
  28.                 if (*it1 != *std::prev(it1))
  29.                     return std::make_pair(false, std::list<char>());
  30.  
  31.                 first.erase(it1);
  32.                 ++it2;
  33.             }
  34.         }
  35.  
  36.         else ++it1, ++it2;
  37.     }
  38.  
  39.     if (it1 == first.end() && it2 == second.end())
  40.         return std::make_pair(true, first);
  41.  
  42.     else if (it1 == first.end())
  43.     {
  44.         while (it2 != second.end())
  45.         {
  46.             if (*it2 != *std::prev(it1))
  47.                 return std::make_pair(false, std::list<char>());
  48.             else
  49.                 second.erase(it2);
  50.         }
  51.  
  52.         return std::make_pair(true, first);
  53.     }
  54.  
  55.     else
  56.     {
  57.         while (it1 != first.end())
  58.         {
  59.             if (*it1 != *std::prev(it2))
  60.                 return std::make_pair(false, std::list<char>());
  61.             else
  62.                 first.erase(it1);
  63.         }
  64.  
  65.         return std::make_pair(true, first);
  66.     }
  67. }
  68.  
  69. int main()
  70. {
  71.     char input1[100], input2[100], input3[100];
  72.     std::scanf("%s\n%s\n%s", input1, input2, input3);
  73.  
  74.     std::list<char> string1, string2, string3;
  75.  
  76.     std::move(input1, input1 + std::strlen(input1), std::back_inserter(string1));
  77.     std::move(input2, input2 + std::strlen(input2), std::back_inserter(string2));
  78.     std::move(input3, input3 + std::strlen(input3), std::back_inserter(string3));
  79.  
  80.     std::pair<bool, std::list<char>> res1 = func(string1, string2);
  81.  
  82.     if (!res1.first)
  83.         std::puts("IMPOSSIBLE");
  84.     else
  85.     {
  86.         std::pair<bool, std::list<char>> res2 = func(res1.second, string3);
  87.  
  88.         if (!res2.first)
  89.             std::puts("IMPOSSIBLE");
  90.  
  91.         else
  92.             for (char elem : res2.second)
  93.                 std::printf("%c", elem);
  94.     }
  95.  
  96.     return 0;
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement