?? 回文.cpp
字號:
//判斷是否回文程序
#include <iostream.h>
const int SM=20;
struct Stack
{
char* stack;
short top;
short StackMaxSize;
};
static void InitStack(Stack& S,int ms)
{
S.stack=new char[ms];
S.top=-1;
S.StackMaxSize=ms;
}
static void ClearStack(Stack& S)
{S.top=-1;}
static void DeleteStack(Stack& S)
{
delete []S.stack;
S.top=-1;
S.StackMaxSize=0;
}
static bool StackEmpty(Stack& S)
{return S.top==-1;}
char Peek(Stack& S)
{
return S.stack[S.top];
}
static void Push(Stack& S,const char& item)
{
S.top++;
S.stack[S.top]=item;
}
static char Pop(Stack& S)
{
S.top--;
return S.stack[S.top+1];
}
static bool StackFull(Stack& S)
{
return S.top==S.StackMaxSize-1;
}
void main()
{
char str[SM];
cin>>str;
Stack www;
InitStack(www,SM);
for(int i=0;str[i]!='\0';i++)
Push(www,str[i]);
int a=0;
while(1)
{
if(Peek(www)==str[a])
{
a++;
Pop(www);
if(a==i-1)
{ cout<<"回文!"<<endl;
break;
}
else
;
}
else
{ cout<<"不回文!"<<endl;
break;
}
}
ClearStack(www);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -