//用栈判断字符串的特定输入-3.17
#include<stdio.h>
#include <string.h> //使用strcmp时使用
#define MAXSIZE 100
typedef char datatype;
typedef struct
{
datatype data[MAXSIZE];
int top;
}sqstack;
//初始化栈
void initstack(sqstack *s)
{
s->top=-1;
}
//入栈
void push(sqstack *s,datatype e)
{
s->top++;
s->data[s->top++]=e;
}
//出栈
datatype pop(sqstack *s)
{if(s->top>=0)
return(s->data[s->top--]);
else printf("all the data has pop./n");
}
int main()
{
int i;
char a[100];
sqstack *data_s;
char e='&',f='@';
char b,c;
initstack(data_s);
for(i=0;i<100;i++)
{
printf("Input the next data: /n");
scanf("%d",a[i]);
push(data_s,a[i]);
if(strcmp(&a[i],&e))break;
}
for(++i;i<100&&strcmp(&a[i],&f);i++)
{
printf("Input the next data: /n");
scanf("%d",a[i]);
b=pop(data_s);
if(strcmp(&a[i],&b))
push(data_s,a[i]);
else
{
printf("the input data is wrong./n");
}
}
printf("the data has inputed./n");
return 1;
}