/*习题4 识别依次读入的一个以字符序列是否为形为序列1&序列2模式的字符序列。 其中序列1和序列2不含&,且序列2为序列1的逆序 a+b&b+a是 a+b&b-a不是*/ //devc++中通过//2006.06.18//Zyq#include <iostream>#include <stack>#include <cstdlib>using namespace std;typedef stack<char> chars; int check(char a[],int n) { chars S; for(int i=0;i<n/2;i++) S.push(*(a+i)); char t; int j=1; int i=n/2+1; if(*(a+i-1)!='&') return 0; else { while(!S.empty()&&j) { j=0; t=S.top(); S.pop(); if(t==*(a+i)) {j=1; i++;} } } if(S.empty()&&j) return 1; else return 0; }

评论