Sign-up....

改个程序,大家帮个忙

以下程序能改成input output 的输入输出格式吗

#include <stdio.h>

#include <malloc.h>

#define Yes 1

#define No 0

typedef int Status;

//------栈的顺序存储表示------------

#define STACK_INIT_SIZE 100

#define STACKINCREMENT 10

typedef struct

{int *base;

int *top;

int stacksize;

}SqStack;

Status InitStack(SqStack &s)

{//构造一个空栈

s.base=(int *)malloc(STACK_INIT_SIZE*sizeof(int));

if(!s.base) return No;

s.top=s.base;

s.stacksize=STACK_INIT_SIZE;

return Yes;

}

Status push(SqStack &s,char e)

{//插入e为新的栈顶元素

if(s.top-s.base>=s.stacksize)

{s.base=(int *)realloc(s.base,(s.stacksize+STACKINCREMENT)*sizeof(int));

if(!s.base) return No;

s.top=s.base+s.stacksize;

s.stacksize+=STACKINCREMENT;

}

*s.top++=e;

return Yes;

}

Status pop(SqStack &s,char &e)

{//若栈不空,则删除S的栈顶元素,用e返回其值,并返回炽OK;否则返回ERROR

if(s.base==s.top) return No;

e=*--s.top;

return Yes;

}

Status StackEmpty(SqStack s)

{if(s.base==s.top) return 1;

else return 0;

}

main()

{char ch1,ch2,c[100];int i;

SqStack s;

InitStack(s);

printf("请输入包括括号表达式:");

scanf("%s",c);

i=0;

while(ch1=c[i++])

{if(ch1=='('||ch1=='{'||ch1=='[')

push(s,ch1);

else if(ch1==')' ||ch1==']' ||ch1=='}')

{ if(StackEmpty(s)) {printf("表达式中的括号不匹配!\n");return No;}

pop(s,ch2);

if(ch2=='(' && ch1!=')') {printf("表达式中的括号不匹配!\n");return No;}

if(ch2=='[' && ch1!=']') {printf("表达式中的括号不匹配!\n");return No;}

if(ch2=='{' && ch1!='}') {printf("表达式中的括号不匹配!\n");return No;}

}

}

if(!StackEmpty(s)) {printf("表达式中的括号不匹配!\n"); return No;}

printf("表达式中的括号匹配!");

printf("\n");

}

[300 byte] By [Breeze] at [2007-8-15 11:18:38]

C/C++

All Classified