- #include "stdio.h"
- #include"malloc.h"
- #define MAX 70
- typedef struct stack{
- char element[MAX+1];
- int top;
- }STACK;
- int push(STACK *s,char arg)
- {
- if(s->top==MAX)
- return(-1);
- else{
- s->top++;
- s->element[s->top]=arg;
- return 0;
- }
- }
- char pop(STACK *s)
- {
- char arg;
- if(s->top==NULL)
- return('\\0');
- else {
- arg=s->element[s->top];
- s->top--;
- return(arg);
- }
- }
- int main()
- {
- STACK *ss;
- int count;int i;
- char ch;
- char a;
- scanf("%d",&count);
- a=getchar();
- ss=(STACK *)malloc(count *sizeof(STACK));
- for(i=0;i<count;i++) ss[i].top=0;
- for( i=0;i<count;i++)
- while((ch=getchar())!='\\n')
- push(&ss[i],ch);
- for( i=0;i<count;i++)
- {
- while((ch=pop(&ss[i]))!='\\0')
- putchar(ch);
- putchar('\\n');
- }
- return 0;
- }
- //该片段来自于http://www.codesnippet.cn/detail/010720134389.html
来源: http://www.codesnippet.cn/detail/010720134389.html