码迷,mamicode.com
首页 > 其他好文 > 详细

HDU-5687-Problem C

时间:2018-10-03 00:49:19      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:turn   ble   init   ++   scan   nbsp   clu   main   ini   

#include"bits/stdc++.h"
using namespace std;
struct tree{
    tree* Next[26];
    int cnt;
}*root;
tree* init(){
    tree* t=(tree*)malloc(sizeof(tree));
    memset(t->Next,NULL,sizeof(t->Next));
    t->cnt=0;
    return t;
}
void in(char* s){
    tree* now=root;
    for(int i=0;s[i];i++){
        int j=s[i]-a;
        if(!now->Next[j])now->Next[j]=init();
        now=now->Next[j];
        now->cnt++;
    }
}
void out(char* s){
    tree* now=root;
    for(int i=0;s[i];i++){
        int j=s[i]-a;
        if(!now->Next[j]){
            puts("No");
            return;
        }
        now=now->Next[j];
    }
    puts("Yes");
}
void era(tree* t){
    for(int i=0;i<26;i++)
    if(t->Next[i])era(t->Next[i]);
    free(t);
}
void de(char* s){
    tree* now=root;
    for(int i=0;s[i];i++){
        int j=s[i]-a;
        if(!now->Next[j])return;
        now=now->Next[j];
    }
    int n=now->cnt;now=root;
    for(int i=0;s[i];i++){
        int j=s[i]-a;
        if(now->Next[j]->cnt==n){
            era(now->Next[j]);
            now->Next[j]=NULL;
            return;
        }
        now=now->Next[j];
        now->cnt-=n;
    }
}
char s1[10],s2[35];
int main(){
    int n;root=init();
    scanf("%d",&n);
    while(n--){
        scanf("%s%s",s1,s2);
        if(s1[0]==i)in(s2);
        else if(s1[0]==s)out(s2);
        else de(s2);
    }
    return 0;
}

 

HDU-5687-Problem C

标签:turn   ble   init   ++   scan   nbsp   clu   main   ini   

原文地址:https://www.cnblogs.com/Angel-Demon/p/9738653.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!