pex12_6.cpp
来自「数据结构C++代码,经典代码,受益多多,希望大家多多支持」· C++ 代码 · 共 45 行
CPP
45 行
#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 + =
减小字号Ctrl + -
显示快捷键?