码迷,mamicode.com
首页 > 其他好文 > 详细

hdu1381 Crazy Search(hash map)

时间:2014-11-11 07:04:26      阅读:231      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   ar   os   sp   for   strong   

题目意思:

给出一个字符串和字串的长度,求出该字符串的所有给定长度的字串的个数(不相同)。

题目分析:
此题为简单的字符串哈hash map问题,可以直接调用STL里的map类。map<string,int> snum;


AC代码:

 

    1. #include<iostream>  
    2. #include<string>  
    3. #include<map>  
    4. using namespace std;  
    5. int main()  
    6. {  
    7.     int t,n,nc;  
    8.     cin>>t;  
    9.     while(t--){  
    10.         string s;  
    11.         map<string,int> snum;  
    12.         cin>>n>>nc>>s;  
    13.         int k=0;  
    14.         int len=s.length();  
    15.         for(int i=0;i<=len-n;i++){  
    16.             string ss=s.substr(i,n);  
    17.             if(snum[ss]==0){  
    18.                 k++;  
    19.                 snum[ss]=1;  
    20.             }  
    21.         }  
    22.         cout<<k<<endl;  
    23.         if(t>1) cout<<endl;  
    24.     }  
    25.     return 0;  

hdu1381 Crazy Search(hash map)

标签:style   blog   http   io   ar   os   sp   for   strong   

原文地址:http://www.cnblogs.com/yuyanbian/p/4088624.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!