回分類題庫
d227: 101OOP Lab Exercise: isPalindrome with stack
出處:

Difficulity : N/A
Accepted : 51 Times | Submit :70 Times | Clicks : 1120
Accepted : 48 Users | Submit : 48 Users | Accepted rate : 100%
Time Limit :10000 ms | Memory Limit : 64000 KBytes
題目加入時間 : 2012-11-05 13:45

Content :

You are ask to write a function to determine a string is a palindrome or not.
You have to use stack to implenet isPalindrome function (push, pop,...etc).  
Notice that, in order to get pass in this exercise, you have to do the following:
1. #include <stack>
2. Use at least push() and pop() provided by stack class to implement isPalindrome function.
3. Submit with your oop account.


The following are stack's member function.
*empty():Test whether container is empty (public member function)
*size():Return size (public member function)
*top():Access next element (public member function)
*push():Add element (public member function)
*pop():Remove element (public member function)


/************************Code Below*************************/
#include <iostream>
#include <stack>
#include <string>
using namespace std;

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 :

orangegnaro
Irisiri
LOL
1221

Sample Output :

orangegnaro is a palindrome.
Irisiri is not a palindrome.
LOL is a palindrome.
1221 is a palindrome.

Hint :


  

Author :

(管理員:oop10105)

  Solve it!   Status Forum (0)

C++
C
JAVA
46763. sy2es956304 (6 ms , 392KB)
43990. oop100703031 (6 ms , 408KB)
42185. oop100703036 (6 ms , 404KB)
42183. oop100703020 (6 ms , 404KB)
42137. oop100703030 (6 ms , 406KB)
沒有解題記錄 50796. nwgs524513cja (82 ms , 166KB)

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