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

    于是他错误的点名开始了

    直接用字典树维护即可,不过这个题其实直接用map也能过…

    字典树:

    // Created by CAD
    #include <bits/stdc++.h>
    using namespace std;
    const int maxn=5e5+5;
    struct trie{
        int nex[maxn][26],cnt=0;
        bool exist[maxn];
        void insert(string s){
            int slen=s.length(),p=0;
            for(int i=0;i<slen;++i){
                int c=s[i]-'a';
                if(!nex[p][c]) nex[p][c]=++cnt;
                p=nex[p][c];
            }
            exist[p]=1;
        }
        bool find(string s){
            int slen=s.length(),p=0;
            for(int i=0;i<slen;++i){
                int c=s[i]-'a';
                if(!nex[p][c]) return 0;
                p=nex[p][c];
            }
            return exist[p];
        }
    };
    trie tr,vis;
    
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(0);
        int n;cin>>n;
    
        for(int i=1;i<=n;++i){
            string s;cin>>s;
            tr.insert(s);
        }
        int m;cin>>m;
        for(int i=1;i<=m;++i){
            string s;cin>>s;
            if(vis.find(s)) cout<<"REPEAT"<<endl;
            else{
                if(tr.find(s)) cout<<"OK"<<endl,vis.insert(s);
                else    cout<<"WRONG"<<endl;
            }
        }
        return 0;
    }
    
    

    map:

    // Created by CAD
    #include <bits/stdc++.h>
    using namespace std;
    
    map<string,bool> exist,vis;
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(0);
        int n;cin>>n;
        for(int i=1;i<=n;++i){
            string s;cin>>s;
            exist[s]=1;
        }
        int m;cin>>m;
        for(int i=1;i<=m;++i){
            string s;cin>>s;
            if(vis[s]) cout<<"REPEAT"<<endl;
            else{
                if(exist[s]) cout<<"OK"<<endl,vis[s]=1;
                else    cout<<"WRONG"<<endl;
            }
        }
        return 0;
    }
    
    
  • 相关阅读:
    PHP5.4中新增的traits
    PHP各版本的区别
    冒泡排序原理
    服务器&linux
    PHP
    excel 导出
    try cache
    sql
    Linux下php安装Redis扩展
    Redis安装部署
  • 原文地址:https://www.cnblogs.com/CADCADCAD/p/13353201.html
Copyright © 2011-2022 走看看