📄 pex12_6.cpp
字号:
#include <iostream.h>
#pragma hdrstop
// include Stack class derived from StackBase
#include "wex12_13.h"
void main(void)
{
char word[30], *p;
Stack<char> S;
int ispal = 1;
// enter a word with no whitespace
cout << "Enter a word: ";
cin >> word;
// push each character of the word on stack S
for(p=word;*p;p++)
S.Push(*p);
// pop the stack, comparing against the characters
// of the word. if any two characters do not match,
// the word is not a palindrome
for(p=word;*p;p++)
if (*p != S.Pop())
{
ispal = 0;
break;
}
// output the result
cout << word;
if (ispal)
cout << " is a palindrome" << endl;
else
cout << " is not a palindrome" << endl;
}
/*
<Run>
Enter a word: amanaplanacanalpanama
amanaplanacanalpanama is a palindrome
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -