Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <functional>
- #include <sstream>
- using namespace std;
- void processString(string &input){
- string result;
- remove_copy_if(input.begin(), input.end(), back_inserter(result), ptr_fun<int, int>(&ispunct));
- for_each(result.begin(), result.end(), [](char &c){
- c = ::toupper(c);
- });
- input = result;
- }
- void solve(string input){
- processString(input);
- int maxLength = 1;
- int low, high, start = 0;
- int len = input.length();
- for(int i = 1; i < len; ++i){
- low = i - 1;
- high = i + 1;
- while(input[low] == input[high] && low >= 0 && high < len){
- if(high - low + 1 > maxLength){
- start = low;
- maxLength = high - low + 1;
- }
- --low;
- ++high;
- }
- low = i - 1;
- high = i;
- while(input[low] == input[high] && low >= 0 && high < len){
- if(high - low + 1 > maxLength){
- start = low;
- maxLength = high - low + 1;
- }
- --low;
- ++high;
- }
- }
- cout << input.substr(start, maxLength) << endl;
- }
- int main(){
- string in;
- while(cin >> in){
- solve(in);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement