设为首页 加入收藏

TOP

倒排文档
2015-07-24 05:55:03 来源: 作者: 【 】 浏览:8
Tags:文档


第一行输出该词所在的行数序号(多个的话,按照从小到大排序输出,中间空格隔开,序号从一开始记),如果没有出现,输出 -1
第二行输出频次排名R的单词出现的次数。
测试数据中的词频的分布如下,可见,排名第3的词,出现的次数为2
I,4
Beijing,2
in,2
love,2
.,1
Bejing,1
a,1
also,1
am,1
and,1
beautiful,1
is,1
life,1
live,1
student,1
there,1

travelling,1


这题很简单,参考答案是这样的:

#include
  
   
#include
   
     #include
    
      #include
     
       #include
       #include
       
         #include
        
          using namespace std; const int NN=100; //单词总数 const int MM=100000; //文本单行最大字符数 /* 文本单行 */ char ss[MM]; /* 统计频次 */ map
         
           Mmap; /* 用于最后的频次排序 */ struct node { int x; string s; }a[NN]; /* 用于最后的频次排序的排序规则 */ bool cmp(node xx,node yy) { if(xx.x==yy.x) return xx.s
          
           yy.x; } bool fun(char *p,string temp) { bool fg=false; //此行中,是否有temp string t=""; for(int i=0;*(p+i);i++) { if(*(p+i)==' ') { if(t.size()>0) { if(Mmap.count(t)==0) { Mmap[t]=1; } else Mmap[t]++; if(t==temp) fg=true; } t=""; } else t+=*(p+i); } if(t.size()>0) { if(Mmap.count(t)==0) { Mmap[t]=1; } else Mmap[t]++; if(t==temp) fg=true; } return fg; } int main() { string temp; int n,R,tol=0; queue
           
            ans; //存放查询单词出现的行数 cin>>temp>>n>>R; getchar(); for(int i=0;i
            
             ::iterator itt = Mmap.begin(); while(itt!=Mmap.end()) { a[tol].s=(*itt).first; a[tol].x=(*itt).second; // cout<<(*itt).first<<" "<<(*itt).second<
             
              0) { int x=ans.front(); ans.pop(); printf("%d",x); while(!ans.empty()) { x=ans.front(); ans.pop(); printf(" %d",x); } puts(""); } else puts("-1"); cout<
               
               

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇HDU 3037 Saving Beans (Lucas定.. 下一篇代理方法关键字Action与Fun的使用

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: