注册 登录
编程论坛 C++教室

判断回文的问题

ou1111 发布于 2010-11-11 11:04, 584 次点击
程序代码:
#include<iostream>
#include<string>
using namespace std;
class stack
{
private:
     int top;
     char s[100];
public:
     stack( )
     { top=0;}
     bool push(char  x)
       {
         if(top<99)
         {
             s[top]=x;
             top++;
             return true;
         }
         else cout<<"over flow";
         return false;
       }
    char pop()
    {
        if(top>0)
        {
            top--;
            return s[top];
        }
        cout<<"stack is empty"<<endl;
        return -1;
    }
};
void main()
{
    stack s;
    int n,ll_strlen;
    int i;
    char *p,*a;
    cout<<"input the string's max length."<<endl;
    cin>>n;
    p=new char[n];
    a=new char[n];
    cout<<"input the string."<<endl;
    cin>>p;
    ll_strlen=strlen(p);

    for(i=0;i<ll_strlen;i++)
        if(s.push(p[i])==false)
        {cout<<"fail.";exit(-1);}

        for(i=0;i<ll_strlen;i++)
        {  a[i]=s.pop();
          cout<<a[i];
     
        } cout<<endl;
       for(i=ll_strlen;i>0;i--)
        {    if(a[i]!=p[i])   
            {cout<<"not"<<endl;exit(0);}
            else
            {cout<<"yes";}
         }

}


[ 本帖最后由 ou1111 于 2010-11-11 11:23 编辑 ]
2 回复
#2
玩出来的代码2010-11-11 23:31
for(i=ll_strlen-1;i>=0;i--)
{
    if(a[i]!=p[i])
    {
        cout<<"not"<<endl;exit(0);
    }
}
        cout<<"Yes"<<endl;
#3
nj_dr_19982011-06-26 21:21
请问要问什么???
1