/* ID: jack5251 PROG: calfflac LANG: C++ */ #include #include #include #include //#include #include #include using namespace std; template class notalpha { public: bool operator ()(const Arg &t) const { if(isalpha(t)) return false; else return true; } }; bool paltest(string str) { remove_if(str.begin(), str.end(), notalpha()); string cp = str; reverse(str.begin(), str.end()); if (str == cp) return true; else return false; } int main() { ifstream fin("calfflac.in"); ofstream fout("calfflac.out"); string start = ""; while(!fin.eof()) { string str; getline(fin, str); start += str; } cout << start << endl; string cp = start; // int mid = start.length()/2; // transform(start.begin(), start.end(), tolower); string longest = ""; for (int x=0; x < start.length(); x++) { for (int y=start.length()-1; y > x + longest.length(); y--) { if (start.at(x) == start.at(y)) if (paltest(start.substr(x, y-x))) { longest = start.substr(x, y-x); y=0; } } } fout << longest.length() << endl << longest << endl; return 0; }