Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <set>
- #include <string>
- using namespace std;
- int main() {
- cin.tie(0);
- ios_base::sync_with_stdio(false);
- string s = "";
- char c;
- set <char> sym;
- int i = 0;
- map <char, vector <int> > m;
- while (cin >> c) {
- s += c;
- sym.insert(c);
- m[c].push_back(i);
- ++i;
- }
- string min = "";
- for (auto now : sym) {
- for (int j = 0; j < m[now].size(); ++j) {
- for (i = j + 1; i < m[now].size(); ++i) {
- string s1 = s.substr(m[now][j], (m[now][i] - m[now][j] + 1));
- string s2 = s1;
- reverse(s2.begin(), s2.end());
- if (s2 == s1 && (s1 < min || min == "")) {
- min = s2;
- }
- }
- }
- }
- cout << min << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement