题目

转载来的,有些stl和string的函数蛮好的:

//numx[i]=string(sx); //把char[]类型转换成string类型

// mat.insert(make_pair(numx[i],0)); //创造一个(string,int)整体——结构体,插入map

//sx[j]=ch[sx[j]-'a'];//把字母转换成相应的数字

//mat.find(numx[i])->second;//返回位置—— 取map当中num[i]对应的键值

#include<cstdio>
#include<cstring>
#include<string>
#include<map>
using namespace std;
char ch[]={'','','','','','','','','','','','','','','','','','','','','','','','','',''};
string numx[];
map<string,int> mat; //int是用来记录要输出的答案——数量的
int main()
{
int cas,n,m;
char sx[];
scanf("%d",&cas);
for(;cas--;)
{
mat.clear();
scanf("%d%d",&n,&m);
for(int i=;i<n;++i)
{
scanf("%s",sx);
numx[i]=string(sx); //把char[]类型转换成string类型
mat.insert(make_pair(numx[i],)); //创造一个(string,int)整体——结构体,插入map
}
for(int i=;i<m;++i)
{
scanf("%s",sx);
for(int j=;j < strlen(sx);++j)
sx[j]=ch[sx[j]-'a'];//把字母转换成相应的数字
if(mat.count( string(sx) )!=)
(mat.find( string(sx) )->second)++;
}
for(int i=;i<n;++i)
printf("%d\n",mat.find(numx[i])->second);
}
return ;
}

//根据百度来的写的:

//string ch = "22233344455566677778889999";//string下标也从0开始

//mapp[ num[i] ] = 0; //保存这种按法相应的答案——种类数的,键值对应

// int len=sx.length(); //string的长度s.length()

//mapp.count(sx)//返回map当中sx的数目——查找mapp当中是否存在sx这个数字串(键),若sx的数目不等于0,说明存在

//mapp[sx]++;//键sx对应的值增加1

#include<stdio.h>
#include<string>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
map<string, int > mapp;
string ch = "";//string下标也从0开始
int main()
{
int n,m,t,i;
string num[];
string sx;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
for(i=;i<n;i++)
{
cin >> num[i];
mapp[ num[i] ] = ; //保存这种按法相应的答案——种类数的
}
for(i=;i<m;i++)
{
cin >> sx;
int len=sx.length(); //string的长度s.length()
for(int j=; j<len; j++)
{
sx[j]=ch[ sx[j]-'a' ];//把字母转换成数字(也是字符型的数字),模拟一下就理解了,string下标从0开始
}
if(mapp.count(sx))//查找mapp当中是否存在sx这个数字串(键),若sx的数目不等于0,说明存在
{
mapp[sx]++;//键sx对应的值数目增加1
}
}
//输出n个健相应的值
for(i=;i<n;i++)
{
printf("%d\n",mapp[num[i]]);
}
}
return ;
}

HDU 4287 Intelligent IME(string,map,stl,make_pair)的更多相关文章

  1. HDU 4287 Intelligent IME(map运用)

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4287 Intellig ...

  2. HDU 4287 Intelligent IME(字典树数组版)

    Intelligent IME Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  3. HDU 4287 Intelligent IME(字典树)

    在我没用hash之前,一直TLE,字符串处理时间过长,用了hash之后一直CE,(请看下图)我自从经历我的字典树G++MLE,C++AC以后,一直天真的用C++,后来的CE就是因为这个,G++才支持这 ...

  4. ACM学习历程—HDU 4287 Intelligent IME(字典树 || map)

    Description We all use cell phone today. And we must be familiar with the intelligent English input ...

  5. HDU 4287 Intelligent IME hash

    Intelligent IME Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?p ...

  6. HDU 4287 Intelligent IME

    Intelligent IME Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  7. Es6(Symbol,set,map,filter)

    首先再讲这几个新东西之前,先说一个Es6中新出的扩展运算符(...) 1.展开运算符,就是把东西展开,可以用在array和object上 比如: let a=[,] let b=[,...a,]//[ ...

  8. 【转】Java学习---Java核心数据结构(List,Map,Set)使用技巧与优化

    [原文]https://www.toutiao.com/i6594587397101453827/ Java核心数据结构(List,Map,Set)使用技巧与优化 JDK提供了一组主要的数据结构实现, ...

  9. C/C++解题常用STL大礼包 含vector,map,set,queue(含优先队列) ,stack的常用用法

    每次忘记都去查,真难啊 /* C/C++解题常用STL大礼包 含vector,map,set,queue(含优先队列) ,stack的常用用法 */ /* vector常用用法 */ //头文件 #i ...

随机推荐

  1. hashCode()和toString()

    hashCode函数和toString函数也在Object类中,同样,所有的类都继承了这2个函数. hashCode函数用于生成哈希码,没有参数,返回值为整型 把u的值作为键存入map中,使用get方 ...

  2. 【转】Java JDBC连接SQL Server2005错误:通过端口 1433 连接到主机 localhost 的 TCP/IP 连接失败

    错误原因如下: Exception in thread "main" org.hibernate.exception.JDBCConnectionException: Cannot ...

  3. 6.24 AppCan移动开发者大会:议程重大更新,报名即将关闭

    大会倒计时2天,议程重大更新,报名通道即将关闭! 创业6年,由AppCan主办的第一届移动开发者大会将在本周五盛大召开.超过100万开发者线上参与.现场1500人规模.50家移动互联企业深度参与.30 ...

  4. hdu 1113 Word Amalgamation

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1113 字符串简单题: stl水过 如下: #include<algorithm> #inc ...

  5. android开发系列之消息机制

    最近接触到一个比较有挑战性的项目,我发现里面使用大量的消息机制,现在这篇博客我想具体分析一下:android里面的消息到底是什么东西,消息机制到底有什么好处呢? 其实说到android消息机制,我们可 ...

  6. golang的函数

    在golang中, 函数是第一类值(first-class object), 即函数可以赋值与被赋值. 换言之, 函数也可以作为ReceiverType, 定义自己的method. 实例: http. ...

  7. LD_PRELOAD

    下面的helloworld会在屏幕上打印出什么内容? 1 2 3 4 5 6 #include <stdio.h> int main(int argc, char* argv[], cha ...

  8. Objective-C-实例变量与属性的关系

    当在一个类创建一个属性,Xcode编译器就会自动产生一个带下划线的同名实例变量: 一般来说,如果getter这个属性采用下划线的方式获取效率更高,而setter采用self.属性名更加合理. 读取实例 ...

  9. 重装win7系统的方法

    1.当电脑可以运行的情况下重装系统: 用傻瓜似的重装系统就可以了,这个简单,不在累赘. 2.当电脑打不看的情况下: 2.1 用光盘安装系统,这个有好多教程,不在累赘. 2.2 用U盘安装方法: 2.2 ...

  10. 56.ISE综合,在chipscope信号列表看不到

    代码写好后,进行逻辑综合,在chipscope上添加被触发的信号时,发现有些在信号列表里看不到,这是因为这些信号没有参与到逻辑电路设计中,产生不想关的电路,综合器会默认优化资源. 还有一种情况是,对于 ...