c语言gets为什么输入不执行,scanf,gets输入有关问题,求各位指教

C/C++ code#include

#include

//当'('和')','['和']'个数配对时调用 返回值:0:配对成功 -1:不成功

int Peidui(char *p)

{

int xx,yy;//记录'('和‘[’的个数

char *ptmp;

ptmp=p;

while( *ptmp !='\0')

{

xx=yy=0;

if( *ptmp == '(' )

{

xx=1;

}

else if( *ptmp == '[')

{

yy=1;

}

else return -1;

if(xx) //如果第一个字符为'('

{

while((*(++ptmp) !='\0') && (xx != 0)) //直到找到配对的')'

{

if(*ptmp == '(')

xx++;

if(*ptmp == '[')

yy++;

if(*ptmp == ')') //当xx为负值时表示有')'出现在'('之前

{

xx--;

if(xx<0)

return -1;

}

if(*ptmp == ']')

{

yy--;

if(yy<0)

return -1;

}

}

if(yy) //()里面有[]不配对的情况

{

return -1;

}

}

if(yy)

{

while((*(++ptmp) !='\0')&&(yy != 0))

{

if(*ptmp == '(')

xx++;

if(*ptmp == '[')

yy++;

if(*ptmp == ')')

{

xx--;

if(xx<0)

return -1;

}

if(*ptmp == ']')

{

yy--;

if(yy<0)

return -1;

}

}

if(xx)

{

return -1;

}

}

}

return 0;

}

int main()

{

int testNum,res,i=0,j=0;

int x=0,y=0,len;

char testData[10010];

scanf("%d",&testNum);

if((testNum<=0) || (testNum>100))

return 0;

for(i=0;i

{

scanf("%s",testData);

len=strlen(testData);

if((len>=10000) && (len==0))

{

i--;

continue;

}

j=0;

while(testData[j] !='\0') //检查并记录输入的字符

{

switch(testData[j])

{

case '(':x++;break;

case ')':x--;break;

case '[':y++;break;

case ']':y--;break;

default:return 0; //不符合输入规则就退出

}

j++;

}

if(x==0 && y==0)

{

res=Peidui(testData);

if(res==0)

printf("Yes\n");

else

printf("No\n");

}

else

printf("No\n");

x=y=0; //注意这里要赋值为0

}

return 0;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值