fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int n, m;
  6. cin >> n >> m;
  7. string s[105], ans = "", rev = "";
  8. for (int i = 0;i < n;i++)
  9. cin >> s[i];
  10. for (int i = 0; i < n;i++)
  11. {
  12. for (int j = i + 1;j < n;j++) {
  13. string x = s[i];
  14. reverse(x.begin(), x.end());
  15. if (s[j] == x)
  16. {
  17. ans += s[i];
  18. break;
  19. }
  20. }
  21. }
  22. for (int i = 0; i < n; i++)
  23. {
  24. bool fla = true;
  25. for (int l = 0, k = s[i].size() - 1;l < k;l++, k--)
  26. {
  27. if (s[i][l] != s[i][k])
  28. {
  29. fla = false;
  30. break;
  31. }
  32. }
  33. if (fla) {
  34. rev= s[i];
  35. break;
  36. }
  37. }
  38. cout << ans.size() * 2 + rev.size()<<"\n";
  39. cout << ans << rev;
  40. reverse(ans.begin(), ans.end());
  41. cout << ans;
  42. return 0;
  43. }
Success #stdin #stdout 0s 5548KB
stdin
9 4
abab
baba
abcd
bcde
cdef
defg
wxyz
zyxw
ijji
stdout
20
ababwxyzijjizyxwbaba