gets的坑

当gets第一个遇到的字符是换行符时,就不往下读了,只能读到一个空串,为了读取下一个字符串,其实我们需要的应该是scanf("%s",s)
题目

#include<cstdio>
using namespace std;
struct node{
    node *lc,*rc; 
    int e;
} nodes[110];
int cur=0;
node * newnode(int e){
    node *t=&nodes[cur++]; 
    t->e=e;
    t->lc=t->rc=0;
    return t;
}
node *insert(node *t,int e){
    if(t==0) return newnode(e);
    if(e< t->e) t->lc=insert(t->lc,e);
    else t->rc=insert(t->rc,e);
    return t;
}
bool comp(node *t1,node *t2){
    if(t1==0&&t2==0) return 1;
    if(t1==0||t2==0) return 0;
    return (t1->e==t2->e)&&comp(t1->lc,t2->lc)&&comp(t1->rc,t2->rc);
}
void preord(node *t){
    if(t==0) return;
    printf("%d",t->e);
    preord(t->lc); preord(t->rc);
}
char s[100];
int main(){
    int n;
    while(scanf("%d",&n)==1&&n){
        //gets(s);  如果用gets,只能得到空串
        scanf("%s",s);
        //printf("%s\n",s);
        node *t=0; cur=0;
        for(int i=0;;++i){
            if(s[i]==0) break;
            t=insert(t,s[i]-'0');
        }
        //preord(t); printf("\n");
        int tmpcur=cur;
        for(int i=0;i<n;++i){
            node *t1=0;
            scanf("%s",s); cur=tmpcur;
            for(int i=0;;++i){
            if(s[i]==0) break;
            t1=insert(t1,s[i]-'0');
            }
            //preord(t1); printf("\n");
           if(comp(t,t1)) printf("YES\n");
            else printf("NO\n");
        }
    }
    return 0;
}

第34行错误

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值