Advertisement
Guest User

Untitled

a guest
Dec 5th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <set>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9. cin.tie(0);
  10. ios_base::sync_with_stdio(false);
  11. string s = "";
  12. char c;
  13. set <char> sym;
  14. int i = 0;
  15. map <char, vector <int> > m;
  16. while (cin >> c) {
  17. s += c;
  18. sym.insert(c);
  19. m[c].push_back(i);
  20. ++i;
  21. }
  22. string min = "";
  23. for (auto now : sym) {
  24. for (int j = 0; j < m[now].size(); ++j) {
  25. for (i = j + 1; i < m[now].size(); ++i) {
  26. string s1 = s.substr(m[now][j], (m[now][i] - m[now][j] + 1));
  27. string s2 = s1;
  28. reverse(s2.begin(), s2.end());
  29. if (s2 == s1 && (s1 < min || min == "")) {
  30. min = s2;
  31. }
  32. }
  33. }
  34. }
  35. cout << min << '\n';
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement