11904 - Palindrome class   

Description

Palindrome is a string that is identical to its reverse, like "LeveL" or "QAQ".

Create a class of palindrome that check whether a given string is a palindrome.

 

main.cpp :

// main.cpp
#include <iostream>
#include "function.h"

using namespace std;

int main()
{

    char word[100001];
    while(cin >> word){

        PalindromeChecker p1(word);
        PalindromeChecker p2;

        p2 = p1;

        p2.reverse();

        if(p1==p2)
            cout << "Yes\n";
        else
            cout << "No\n";
    }

    return 0;
}

 

function.h : 

// function.h
#include <iostream>
#include <string>

using namespace std;

class PalindromeChecker
{
private:
    static const int MAXWORDLENTH=100001;
    char word[MAXWORDLENTH];//store the input string

public:

    PalindromeChecker();
    PalindromeChecker(const char*);
    PalindromeChecker& operator=(const PalindromeChecker& p);
    void reverse();
    friend bool operator== (PalindromeChecker &p1, PalindromeChecker &p2);

};

 

Note:
1. This problem involves three files.
  • function.h: Class definition of PalindromeChecker.
  • function.cpp: Member-function definitions of PalindromeChecker.
  • main.cpp: A driver program to test your class implementation.
2. For OJ submission:
  • Step 1. Include function.h into function.cpp and then implement your function.cpp. (You don’t need to modify function.h and main.cpp)
  • Step 2. Submit the code of function.cpp into submission block.
  • Step 3. Check the results and debug your program if necessary.

Input

The input consists of multiple lines, each line contains a string.

The length of each string is less than 100000. (Defined in MAXWORDLENTH)

The number of test case is less than 1000

Output

Output "Yes" if it's a palindrome, "No" if it's not.

Sample Input  Download

Sample Output  Download

Partial Judge Code

11904.cpp

Partial Judge Header

11904.h

Tags




Discuss