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);
};
Output "Yes" if it's a palindrome, "No" if it's not.