Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <windows.h>
- #include <string>
- #include <vector>
- #include <algorithm>
- using namespace std;
- int main()
- {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- system("color 0A");
- cout << "Введите число любой длины" << endl;
- string s;
- getline(cin, s);
- vector<string> box;
- for (size_t left = 0u; left < s.size() - 1u; ++left)
- {
- for (size_t right = left + 1u; right < s.size(); ++right)
- {
- bool flag = true;
- size_t ind = 0u;
- for (size_t u = left; u <= right; ++u)
- {
- if (s[u] != s[right - ind++])
- {
- flag = false;
- break;
- }
- }
- if (flag)
- {
- string temp;
- for (size_t u = left; u <= right; ++u)
- {
- temp.push_back(s[u]);
- }
- box.push_back(temp);
- }
- }
- }
- auto predicate = [](string s1, string s2)
- {
- return s1.size() > s2.size();
- };
- sort(box.begin(), box.end(), predicate);
- auto max_len = box[0u].size();
- cout << "Самый длиный(ые) палиндром(ы) в числе" << endl;
- for (const auto &word : box)
- {
- if (word.size() == max_len)
- {
- cout << word << endl;
- }
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement