📄 pex5_6.cpp
字号:
#include <iostream.h>
#pragma hdrstop
typedef char DataType;
#include "astack.h"
#include "aqueue.h"
void main (void)
{
// S holds non-blank chars of the string in reverse
Stack S;
// Q holds non-blank chars of the string
Queue Q;
// line contains possible palindrome, p scans line
char line[128], *p = line;
int ispalindrome = 1;
cout << "Enter a possible palindrome: ";
cin.getline(line,128,'\n');
// scan the string, pushing each non-blank character onto Q
// and inserting each into Q
while(*p != NULL)
{
if (*p != ' ')
{
S.Push(*p);
Q.QInsert(*p);
}
p++;
}
// pop stack and delete from the queue. if the two
// characters are not equal, the string is not a palindrome
while(!S.StackEmpty())
if (S.Pop() != Q.QDelete())
{
ispalindrome = 0;
break;
}
if (ispalindrome)
cout << '"' << line << '"' << " is a palindrome."
<< endl;
else
cout << '"' << line << '"' << " is not a palindrome."
<< endl;
}
/*
<Run #1>
Enter a possible palindrome: madam im adam
"madam im adam" is a palindrome.
<Run #2>
Enter a possible palindrome: confer
"confer" is not a palindrome.
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -