加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

P3879 [TJOI2010]阅读理解

发布时间:2020-12-15 08:24:54 所属栏目:Java 来源:网络整理
导读:P3879 [TJOI2010]阅读理解 做法1:map+vector(直接看代码,不解释) 做法2:trie树,在每个单词的末尾标记上是属于哪个文章的就可以了 #include iostream #include cstdio #include queue #include algorithm #include map #include cstring #define inf 2147483

P3879 [TJOI2010]阅读理解
做法1:map+vector(直接看代码,不解释)
做法2:trie树,在每个单词的末尾标记上是属于哪个文章的就可以了

#include <iostream>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <map>
#include <cstring>
#define inf 2147483647
#define N 1000010
#define p(a) putchar(a)
#define For(i,a,b) for(int i=a;i<=b;++i)
//by war
//2019.8.12
using namespace std;
int n,m,q,t;
string s;

map<string,vector<int> >a;

void in(int &x){
    int y=1;char c=getchar();x=0;
    while(c<0||c>9){if(c==-)y=-1;c=getchar();}
    while(c<=9&&c>=0){ x=(x<<1)+(x<<3)+c-0;c=getchar();}
    x*=y;
}
void o(int x){
    if(x<0){p(-);x=-x;}
    if(x>9)o(x/10);
    p(x%10+0);
}

signed main(){
    in(n);
    For(i,1,n){
        in(m);
        For(j,m){
            cin>>s;
            a[s].push_back(i);
        }
    }
    in(q);
    For(ii,q){
        cin>>s;
        t=a[s].size()-1;
        For(i,0,t)
            if(i==0||a[s][i]!=a[s][i-1]){
                if(i!=0) p( );
                o(a[s][i]);
            }
        p(n);
    }
    return 0;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读