回分類題庫
d165: OOP Lab Exercise: isPalindrome with charStack
出處:

Difficulity : N/A
Accepted : 81 Times | Submit :415 Times | Clicks : 1740
Accepted : 64 Users | Submit : 66 Users | Accepted rate : 97%
Time Limit :10000 ms | Memory Limit : 64000 KBytes
題目加入時間 : 2010-04-12 22:25

Content :

You are ask to write a function to determine a string is a palindrome or not. It is similar to assignment 1 except you have to include "stack.h". (stored in judge system.)

You have to use this charStack to implenet isPalindrome function (push, pop,...etc). 

The class header files can be located below, you can assume that stack.h is well implemented.

Notice that, in order to get pass in this exercise, you have to do the following:

1.  #include "stack.h"  and  #include "std_lib_facilities.h"

2. Use at least push() and pop() provided by charStack class to implement isPalindrome function.

3.  Submit wirth your oop account.

 

The following are charStack header file and sample main function.

 //stack.h
#ifndef _CHAR_STACK
#define _CHAR_STACK
#include <vector>

using namespace std;
class charStack {
    public:
        charStack();  // constructor; initialize top to 0
        bool isempty() const;
        char pop();
       void push(char c);
        char peek() const;//return the top without removing it
    private:
        vector<char> elements;
        int top;
};

#endif

===============================================

#include "std_lib_facilities.h"
#include "stack.h"


bool isPalindrome(string s){
    // Your code here.
}

int main(){
    string s;
    while(cin >> s){
        string result;
        isPalindrome(s) ? result = "": result = "not ";
        cout << s << " is " << result << "a palindrome." << endl;
    }
    return 0;
}

Input :

Each line is a test case. There are several cases.

Output :

For each test case string S output a line contains the followings:

if S is a palindrome:

S is a palindrome.           

or S is not a palindrome:

S is not a palindrome.

Sample Input :

12321
5566

Sample Output :

12321 is a palindrome.
5566 is not a palindrome.

Hint :


  

Author :


  Solve it!   Status Forum (0)

C++
C
JAVA
20336. oop98703042 (74 ms , 394KB)
20436. oop98703050 (76 ms , 400KB)
20412. oop98703043 (76 ms , 404KB)
20446. oop98703020 (78 ms , 406KB)
20440. oop98703031 (78 ms , 402KB)
沒有解題記錄 50706. nwgs524513cja (306 ms , 6404KB)
50705. nwgs524513cja (328 ms , 6408KB)

執行時間會受很多因素影響因此僅供參考,主機等級請看這裡