All pastes #556581 Raw Edit

Mine

public text v1 · immutable
·published 2007-06-10 17:31 UTC
rendered paste body
/*
ID: jack5251
PROG: calfflac
LANG: C++
*/
 
#include <fstream>
#include <string>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <cctype>
 
using namespace std;

bool paltest(string Test)
{
    
    size_t pos;
    
    while( (pos = Test.find_first_of("`~!@#$%^&*()-_=+{}|[]\\:;\"\'<>,.?/\t\r\n")) != string::npos)
       Test.erase(pos, 1);
    
    while( (pos = Test.find(" ")) != string::npos)
       Test.erase(pos, 1);
    
    while( (pos = Test.find_first_of("ABCDEFGHIJKLMNOPQRSTUVWXYZ")) != string::npos)
       Test[pos] = tolower(Test[pos]);
    
    bool check = false;
    
    string temp = "";
    
    for(int x=Test.length() - 1; x>=0; x--)
    {
            temp += Test.at(x);
    }
    if(Test == temp)
            check = true;
    
    if(check)
       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;
    }
 
    string longest = "";
 
    for (int x=0; x < start.length(); x++)
    {
        for (int y=start.length()-1; y > x + longest.length(); y--)
        {
            if (tolower(start.at(x)) == tolower(start.at(y)))
            {
                if (paltest(start.substr(x, y)))
                {
                    longest = start.substr(x, y);
                    y=0;
                }
            }
        }
    }
 
    fout << longest.length() << endl << longest << endl;
 
    return 0;
}