zoukankan      html  css  js  c++  java
  • P2580 于是他错误的点名开始了

    #include <bits/stdc++.h>
    # define LL long long
    using namespace std;
    
    const int INF=0x7fffffff;
    
    int n, m;
    
    struct Trie{
        bool isword;
        int cnt;
        Trie* children[26];
    
        Trie(){
            isword=false;
            cnt=0;
            for(int i=0;i<26;++i){
                children[i]=nullptr;
            }
        }
    };
    Trie* root;
    
    void build(string s){
        Trie* cur=root;
        for(char c:s){
            if(cur->children[c-'a']==nullptr){
                cur->children[c-'a']=new Trie();
            }
            cur=cur->children[c-'a'];
        }
        cur->isword=true;
    }
    
    int search(string s){
        Trie* cur=root;
        for(char c:s){
            if(cur->children[c-'a']==nullptr) return 0;
            cur=cur->children[c-'a'];
        }
        if(cur->isword==false) return 0;
        if(cur->cnt>0) return 2;
        cur->cnt=1;
        return 1;
    }
    
    int main(){
        scanf("%d", &n);
        root=new Trie();
        for(int i=1;i<=n;++i){
            string s;
            cin>>s;
            build(s);
        }
        scanf("%d", &m);
        for(int i=1;i<=m;++i){
            string s;
            cin>>s;
            int res=search(s);
            if(res==0) printf("WRONG
    ");
            else if(res==2) printf("REPEAT
    ");
            else printf("OK
    ");
        }
        return 0;
    }
  • 相关阅读:
    转:中国菜刀用法
    转的:burp suite小例子
    [转]阿里前员工评马云
    Burp Suite使用教程
    C++实现按绩点排名
    C++排列对称串
    C++实现01串排序
    C++判断五位以内的对称素数
    C++12!配对
    C++列出完数
  • 原文地址:https://www.cnblogs.com/FEIIEF/p/12273481.html
Copyright © 2011-2022 走看看