注册 登录
编程论坛 数据结构与算法

帮忙看看,大神们。主要是交到oj上市wa ;

swustxf 发布于 2015-04-21 14:25, 2040 次点击
#include <iostream>
#include <malloc.h>
using namespace std ;
#define maxsize 1001

struct stack
{
                char data[maxsize] ;
                int top ;
};


bool push(stack  *&s , char e)
{
      if(s->top == maxsize-1)
                return false ;
      s->top++ ;
      s->data[s->top] = e ;
      return true ;
}

char pop(stack *&s)
{
                char e ;
                e = s->data[s->top] ;
                s->top-- ;
                return e;
}

int main()
{
                stack *s  = new stack ;
                s->top = -1 ;
                char str1[101] ,str2[101];
                int i = 0 ;
                bool flag = 0;
                while(true)
                {
                                cin>>str1[i] ;
                                if(str1[i] == '@')
                                                break ;
                                i++;
                }
                int m ;
                for(m = 0 ;m<i ;m++)
                       push(s,str1[m]);
                int j = 0 ;
                while(true)
                {
                      char e = pop(s) ;
                                cin>>str2[j] ;
                                if(str2[j] == e)
                                    flag = 1;
                                if(str2[j] == '#')
                                                break ;
                                j++;
                }
                if(flag == 1)
                    cout<<"yes!" ;
                else
                    cout<<"no!" ;
                return 0 ;

}

编写一程序,识别依次读入的一个以“#”为结束符的字符序列是否为形如“序列1@序列2”模式的字符序列。期中序列1和序列2中都不含字符“@”,且序列2是序列1的逆序列。例如“a+b@b+a”是满足条件的序列字符,而“1+3@3-1”则不是。
0 回复
1