zoukankan      html  css  js  c++  java
  • hdu 1251 统计拼图

    二手tire木;

    Basic应用程序

     谈到很具体的 点击打开链接

    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #define max 20
    using namespace std;
    char  w[6];
    struct node{
        bool a;
        int chile[26];
        int q;//前缀出现次数
        node(){
            q=false;
            q=0;
            memset(chile,0,sizeof(chile));
        }
    }t[500000];
    
    int sz=1;
    void insert(char *w)
    {
        int len=strlen(w);
        int s=0;
        for(int i=0;i<len;i++)
        {
            int y=w[i]-'a';
            if(t[s].chile[y]==0)
            {
                t[s].chile[y]=sz++;
            }
            s=t[s].chile[y];//下一个结点
            t[s].q++;
        }
        t[s].a=1;
    }
    
    int show(char *w)
    {
        int len=strlen(w);
        int s=0;
        for(int i=0;i<len;i++)
        {
            int y=w[i]-'a';
            if(t[s].chile[y]==0)
                return 0;
            s=t[s].chile[y];
        }
        return t[s].q;
    }
    int main()
    {
        char s[50];
        while(gets(s))
        {
            int len=strlen(s);
            if(len==0) break;
            insert(s);
        }
        while(gets(s))
        {
            printf("%d
    ",show(s));
        }
        return 0;
    }
    


    版权声明:本文博主原创文章,博客,未经同意不得转载。

  • 相关阅读:
    Promise、Async、await
    Generator
    模块化
    继承
    原型
    == vs ===
    深浅拷贝
    this
    nodejs中搭建服务器
    sql中constraint主要是增加约束
  • 原文地址:https://www.cnblogs.com/blfshiye/p/4841801.html
Copyright © 2011-2022 走看看