代号-K
发表于 2020-2-27 11:35:46
学习一下
Lizzie0627
发表于 2020-3-9 16:02:43
如果括号里有其他内容该怎么解,就像有些笔试题把括号当成包装盒,把括号里面的内容当成礼物,然后判断盒子里有没有礼物
wmj1
发表于 2020-3-11 13:49:31
可见
baitang
发表于 2020-3-12 16:49:11
支持
Fidio
发表于 2020-3-24 22:34:08
嗯嗯
不会编程的男人
发表于 2020-4-8 19:02:43
用于学习
不会编程的男人
发表于 2020-4-8 19:04:50
用于学习
1917858989
发表于 2020-4-14 13:20:58
我要看代码
chjh42
发表于 2020-5-7 08:17:49
bangbangbang
哦啦啦啊
发表于 2020-6-1 22:46:19
请问代码是什么
少吃xm多喝rs
发表于 2020-7-7 18:15:25
看一哈
blackice
发表于 2020-9-18 09:54:08
比较比较
arenmy
发表于 2020-10-11 12:05:13
有点东西
芜湖起飞1
发表于 2020-10-15 19:49:11
啊这{:10_269:}{:10_269:}
基某人
发表于 2020-10-16 00:04:41
感谢
joy.Z.
发表于 2020-10-18 03:41:32
来看看源代码!
黑白客
发表于 2020-10-22 02:02:00
#include<stdio.h>
#include<stdlib.h>
#define stack_init_size 40
typedef struct stack
{
char* base;
char* top;
int stacksize;
}sqstack;
void initstack(sqstack* s)
{
s->base = (char*)malloc(stack_init_size * sizeof(sqstack));
if (!s->base)exit(0);
s->top = s->base;
s->stacksize = stack_init_size;
}
void push(sqstack* s, char e)
{
if (!s->base)exit(0);
s->top = s->base + s->stacksize;
s->stacksize += 10;
*s->top++ = e;
}
voidpop(sqstack*s, char* e)
{
if (s->top == s->base) return 0;
e = *--s->top;
}
int main()
{
int* base;
int* top;
int stacksize;
sqstack s;
initstack(&s);
char e = {0};
int count = 0;
printf("input:");
scanf_s("%c", &e,1);
if (e != '\n' || e !=')' || e != ']' || e != '}')//第一个字符的判断
{
push(&s, e);
}
else return 0;
while (e != '\n')
{
scanf_s("%c", &e, 1);
char* p;
p = s.top - 1;
switch (e)
{
case')':
if (*p == '[' || *p == '}')
{
printf("0");
}
break;
if (*(p - 1) == '(')
{
pop(&s, &e);
}
continue;
case']':
if (*p == '(' || *p == '}')
{
printf("0");
}
break;
if (*(p - 1) == '[')
{
pop(&s, &e);
}
continue;
case'}':
if (*p == '(' || *p == '[')
{
printf("0");
}
break;
if (*(p - 1) == '{')
{
pop(&s, &e);
}
continue;
case '(':
push(&s, &e);
continue;
case '[':
push(&s, &e);
continue;
case '{':
push(&s, e);
continue;
}
}
if (s.top == s.base)
printf("1");
else
printf("0");
}
云端之梦
发表于 2020-10-23 08:14:28
#include <stdio.h>
#include <stdlib.h>
typedef int Status;
typedef int Elemtype;
#define ERROR 0
#define OK 1
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
#define x 20
typedef struct {
Elemtype *top;
Elemtype *base;
int stacksize;
}Stack;
Stack S;
Status Initstack(Stack S)
{
if(S.base==0)
return 0;
S.base=(Elemtype*)malloc(STACK_INIT_SIZE*sizeof(Elemtype));
S.top=S.base;
S.stacksize=STACK_INIT_SIZE;
return 1;
}
Status Pushstack(Stack &S,Elemtype &e)
{
if(S.base==S.top)
return 0;
if(S.top-S.base==S.stacksize)
{
S.base=(Elemtype*)realloc(S.base,(S.stacksize+STACKINCREMENT)*sizeof(Elemtype));
S.top=S.base+S.stacksize;
S.stacksize=S.stacksize+STACKINCREMENT;
}
*S.top=e;
S.top++;
return 1;
}
Status Popstack(Stack &S,Elemtype e)
{
if(S.base==S.top)
return 0;
e=*S.top;
S.top--;
return 1;
}
int matchstack(char *p)
{
Elemtype e;
while(*p!=0)
{
if(*p=='('||*p=='[')
{
Pushstack(S,e);
}
*(p++);
if(*p==')'||*p==']')
{
Popstack(S,e);
}
*(p++);
}
if(S.base>S.top)
return 0;
else
return 1;
}
int main()
{
char c;
gets(c);
if(matchstack(c)==1)
printf("成功\n");
else
printf("失败\n");
return 0;
}
beannaeb
发表于 2020-10-25 00:21:35
感谢
xzh3000
发表于 2020-10-25 10:07:15
nb