Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <string>
- #include <math.h>
- #include <algorithm>
- #include <vector>
- #include <set>
- #include <sstream>
- using namespace std;
- bool cor(string s)
- {
- long long j=0, i=s.size()-1;
- bool what=true;
- while (i >= j)
- {
- if (s[i] == s[j])
- {
- i--;
- j++;
- }
- else
- {
- what = false;
- break;
- }
- }
- if (what)
- return true;
- else
- return false;
- }
- int main()
- {
- string s, prom;
- string max="";
- long long maxpos=10000000;
- cin >> s;
- for(int i=0;i<s.size();i++)
- for (int j = i + 1; j <= s.size(); j++)
- {
- prom = s.substr(i, j-i);
- if (cor(prom))
- {
- if (prom.size() > max.size())
- {
- max = prom;
- maxpos = i;
- }
- else
- if (prom.size() == max.size())
- if (i < maxpos)
- {
- max = prom;
- maxpos = i;
- }
- }
- }
- cout << max;
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment