题目意思:

给出一个字符串和字串的长度,求出该字符串的全部给定长度的字串的个数(不同样)。

题目分析:

此题为简单的字符串哈hash map问题,能够直接调用STL里的map类。

map<string,int> snum;

AC代码:

#include<iostream>
#include<string>
#include<map>
using namespace std;
int main()
{
int t,n,nc;
cin>>t;
while(t--){
string s;
map<string,int> snum;
cin>>n>>nc>>s;
int k=0;
int len=s.length();
for(int i=0;i<=len-n;i++){
string ss=s.substr(i,n);
if(snum[ss]==0){
k++;
snum[ss]=1;
}
}
cout<<k<<endl;
if(t>1) cout<<endl;
}
return 0;
}

hdu1381 Crazy Search(hash map)的更多相关文章

  1. [poj1200]Crazy Search(hash)

    Crazy Search Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 26713 Accepted: 7449 Descrip ...

  2. poj 1200 Crazy Search(hash)

    题目链接:http://poj.org/problem?id=1200 思路分析:从数据来看,该题目使用线性时间算法,可见子串的比较是不可能的:使用hash可以在常数时间内查找,可以常数时间内判重, ...

  3. $Hdu1381\ Crazy\ Search$

    前置芝士 :string 的 基本用法 string s = "hello world" ; string tmp(s,0,5) ; cout << tmp <& ...

  4. (map string)Crazy Search hdu1381

    Crazy Search Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  5. POJ-1200 Crazy Search,人生第一道hash题!

                                                        Crazy Search 真是不容易啊,人生第一道hash题竟然是搜博客看题解来的. 题意:给你 ...

  6. hdu 1381 Crazy Search

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1381 Crazy Search Description Many people like to sol ...

  7. Hash Map (Hash Table)

    Reference: Wiki  PrincetonAlgorithm What is Hash Table Hash table (hash map) is a data structure use ...

  8. POJ 1200:Crazy Search(哈希)

    Crazy Search Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 32483   Accepted: 8947 Des ...

  9. POJ1200 A - Crazy Search(哈希)

    A - Crazy Search Many people like to solve hard puzzles some of which may lead them to madness. One ...

随机推荐

  1. iOS7 文本转语音 AVSpeechSynthesizer

    OS7 的这个功能确实不错.我刚试了下,用官方提供的API ,简单的几句代码就能实现文本转语音! Xcode 5.0 工程建好后首先把AVFoundation.framework 加入到工程 AVSp ...

  2. C# WPF Datagrid的筛选

    public static void SearchResult(DataGrid dg,string condition) { #region string code = string.Empty; ...

  3. windows phone 三种数据共享的方式(8)

    原文:windows phone 三种数据共享的方式(8) 本节实现的内容是数据共享,实现的效果描述:首先是建立两个页面,当页面MainPage通过事件导航到页面SecondPage是,我们需要将Ma ...

  4. sql语句用'in'执行多条语句时候,执行错误的解决方法

    一般报错是出现,无法将nvarchar类型转换为int类型 这是因为 SqlParameter  带参数  是不能用  , 分割的. 第一种解决方法就是  不用 SqlParameter  带参数的s ...

  5. 多线程——达到Runnable介面

    部分博客(多线程--继承Thread类)介绍了java多线程的第一种实现方法--继承Thread类.这篇博客介绍另外一种方法--实现Runnable接口,并实现run方法. 还用上篇博客的样例.如今用 ...

  6. svn 使用(一个)

    一个. 安装svn  server(操作系统centos) yum install subversion 通过 subversion -v 如果成功安装命令来查看 温馨提示不承担任何subversio ...

  7. windows下使用lighttpd+php(fastcgi)+mysql

    一.windows下编译配置执行lighttpd 1.下载并安装cygwin. 2.下载lighttpd源码并解压3.在cygwin环境下进入lighttpd的解压文件夹后,执行: 1> ./c ...

  8. JAVA基础编程50题(10-12题)具体解释

    一.描写叙述 1.一球从m米高度自由落下.每次落地后反跳回原高度的一半:再落下,求它在 第n次落地时.共经过多少米?第10次反弹多高? 2.有1.2.3.4个数字.能组成多少个互不同样且无反复数字的三 ...

  9. Source Insight 3.X 插件支持utf8,完美解决中国乱码,连接到美丽的轮廓

    上次SI多标签插件之后,由于公司内部编码改为utf8编码,因此特意做了这个Source Insight 3.X utf8插件. 下载地址:http://pan.baidu.com/s/1mgyZous ...

  10. c++爱问的面试问题

    1.static_cast,dynamic_cast,reinterpret_cast,const_cast四种转换. 2.const行为 3.malloc/free, new/delete差额 4. ...