⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pex12_6.cpp

📁 数据结构C++代码,经典代码,受益多多,希望大家多多支持
💻 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 + -