SHARE
TWEET

Untitled

a guest Oct 18th, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <assert.h>
  6. #include <cmath>
  7. #include <string>
  8.  
  9. using namespace std;
  10.  
  11. size_t n;
  12.  
  13. bool check(string s)
  14. {
  15.     size_t si = s.length();
  16.     for (size_t i = 0; i < si / 2; i++)
  17.         if (s[i] != s[si - i - 1])
  18.             return false;
  19.     return true;
  20. }
  21.  
  22.  
  23. string reverse(string s)
  24. {
  25.     string t = "";
  26.     size_t si = s.length();
  27.     for (size_t i = si; i > 0; i--)
  28.         t += s[i - 1];
  29.     return t;
  30. }
  31.  
  32. int solve(const vector<string> & a, const vector<string> &b, const int rv_ans)
  33. {
  34.     vector<string> nor = a;
  35.     vector<string> inv = b;
  36.     inv.push_back("-");
  37.     inv.push_back("a");
  38.     sort(inv.begin(), inv.end());
  39.    
  40.     for (size_t i = 0; i < n; i++)
  41.     {
  42.         size_t si = nor[i].length();
  43.         for (size_t j = 1; j <= si; j++)
  44.         {
  45.             string p = nor[i].substr(0, j);
  46.             string s = *lower_bound(inv.begin(), inv.end(), p);
  47.             string rev = reverse(s);
  48.             if (s == nor[i].substr(0, j) && rev != nor[i])
  49.             {
  50.                 string t = nor[i].substr(j, nor[i].length());
  51.                 for (size_t k = 0; k < n; k++)
  52.                 {
  53.                     if (i != k && check(t + nor[k]) && rev != nor[k])
  54.                     {
  55.                         string ans = nor[i] + " " + nor[k] + " " + rev;
  56.                         if (rv_ans == 0) cout << ans;
  57.                         else cout << reverse(ans);
  58.                         return 23;
  59.                     }
  60.                 }
  61.             }
  62.         }
  63.     }
  64.     return 0;
  65. }
  66.  
  67. int main()
  68. {
  69.     freopen("answer.in", "r", stdin);
  70.     freopen("answer.out", "w", stdout);
  71.     cin >> n;
  72.     vector<string> nor, inv;
  73.     for (size_t i = 0; i < n; i++)
  74.     {
  75.         string s;
  76.         cin >> s;
  77.         nor.push_back(s);
  78.         inv.push_back(reverse(s));
  79.     }
  80.     if (solve(nor, inv, 0) == 23) return 0;
  81.     if (solve(inv, nor, 1) == 23) return 0;
  82.     cout << "Sorry, but I don't know question!\n";
  83. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top