2019/2/20训练日记+map/multi map浅谈
Most crossword puzzle fans are used to anagrams — groups of words with the same letters in different
orders — for example OPTS, SPOT, STOP, POTS and POST. Some words however do not have this
attribute, no matter how you rearrange their letters, you cannot form another word. Such words are
called ananagrams, an example is QUIZ.
Obviously such definitions depend on the domain within which we are working; you might think
that ATHENE is an ananagram, whereas any chemist would quickly produce ETHANE. One possible
domain would be the entire English language, but this could lead to some problems. One could restrict
the domain to, say, Music, in which case SCALE becomes a relative ananagram (LACES is not in the
same domain) but NOTE is not since it can produce TONE.
Write a program that will read in the dictionary of a restricted domain and determine the relative
ananagrams. Note that single letter words are, ipso facto, relative ananagrams since they cannot be
“rearranged” at all. The dictionary will contain no more than 1000 words.
Input
Input will consist of a series of lines. No line will be more than 80 characters long, but may contain any
number of words. Words consist of up to 20 upper and/or lower case letters, and will not be broken
across lines. Spaces may appear freely around words, and at least one space separates multiple words
on the same line. Note that words that contain the same letters but of differing case are considered to
be anagrams of each other, thus ‘tIeD’ and ‘EdiT’ are anagrams. The file will be terminated by a line
consisting of a single ‘#’.
Output
Output will consist of a series of lines. Each line will consist of a single word that is a relative ananagram
in the input dictionary. Words must be output in lexicographic (case-sensitive) order. There will always
be at least one relative ananagram.
Sample Input
ladder came tape soon leader acme RIDE lone Dreis peat
ScAlE orb eye Rides dealer NotE derail LaCeS drIed
noel dire Disk mace Rob dries
Sample Output
Disk
NotE
derail
drIed
eye
ladder
soon
关于昨晚的题,按昨天的思路写出来下面的代码,写一个比较函数,就能出结果,但是这毕竟是STL训练,而且当数据量上去的时候,这样的写法绝对会超时,数组绝对盛不下。
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<vector>
#include<set>
#include<cstring>
using namespace std;
int Count=0;
struct abc
{
string a;
string b;
};
void zh(string m,string &n);
int main()
{
abc x[2000];
while(cin>>x[Count].a)
{
cin>>x[Count].a;
if(x[Count].a=="#") break;
zh(x[Count].a,x[Count].b);
Count++;
}
}
void zh(string m,string &n)
{
char q[30];
memset(q,0,sizeof(char)*30);
for(int i=0;i<m.length();i++)
{
q[i]=m[i];
q[i]=tolower(q[i]);
}
sort(q,q+m.size());
n=q;
}
所以悬崖勒马,赶紧选用其它容器。
map/multimap
map/multimap映射容器的元素数据是由一个Key和一个Value成的,key与映照value之间具有一一映照的关系。
map/multimap容器的数据结构也采用红黑树来实现的,map插入元素的键值不允许重复,类似multiset,multimap的key可以重复。比较函数只对元素的key进行比较,元素的各项数据只能通过key检索出来。虽然map与set采用的都是红黑树的结构,但跟set的区别主要是set的一个键值和一个映射数据相等,Key=Value。
map<first,second> a;
//map,会按照first(键值)排序(查找也是);
map/multimap用法
头文件
#include< map >
map成员函数
begin() //返回指向 map 头部的迭代器
clear() // 删除所有元素
count() //返回指定元素出现的次数
empty() // 如果 map 为空则返回 true
end() //返回指向 map 末尾的迭代器
erase() // 删除一个元素
find() // 查找一个元素
insert() //插入元素
key_comp() //返回比较元素 key 的函数
lower_bound() //返回键值>=给定元素的第一个位置
max_size() //返回可以容纳的最大元素个数
rbegin() //返回一个指向 map 尾部的逆向迭代器
rend() //返回一个指向 map 头部的逆向迭代器
size() //返回 map 中元素的个数
swap() //交换两个 map
upper_bound() //返回键值>给定元素的第一个位置
value_comp() //返回比较元素 value 的函数
创建map对象
#include<iostream>
#include<map>
using namespace std;
map<int,char>mp;//定义map容器
创建结构体map对象
struct student{
int birth;
string name;
};
int id;
typedef map<int,student> Student;//本语句后所有语句Student==map<int,student>
插入结构体对象
接上文代码
Stduent a;
cin>>id>>student.birth>>student.name;
a.insert(make_pair(id,student);
通过map容器使得上述解题方式更简便。
2019/2/20训练日记+map/multi map浅谈的更多相关文章
- 2019.06.18训练日记(赞FLS)
之前打了几场比赛,有很多题没做出来,这些题无论是知识点不会,还是说在当时时间和思路的影响下没有做出来,这都应该做出来,至少现在必须做出来,本来打算专心复习,分数高了,好保研,但是想了想如果局限于只把学 ...
- LinkedHashSet、Map、Map接口HashMap、Hashtable,TreeSet、TreeMap、如何选择使用集合实现类,Collections工具类
一.Set接口实现类LinkedHashSet 实现继承图: 1.LinkedHashSet的全面说明 1) LinkedHashSet是 HashSet的子类 2) LinkedHashSet底层是 ...
- 浅谈Java中的Set、List、Map的区别(转)
对JAVA的集合的理解是想对于数组: 数组是大小固定的,并且同一个数组只能存放类型一样的数据(基本类型/引用类型),JAVA集合可以存储和操作数目不固定的一组数据. 所有的JAVA集合都位于 java ...
- Map生成器 map适配器如今能够使用各种不同的Generator,iterator和常量值的组合来填充Map初始化对象
Map生成器 map适配器如今能够使用各种不同的Generator,iterator和常量值的组合来填充Map初始化对象 package org.rui.collection2.map; /** * ...
- 图像的影像地图超链接,<map>标签浅谈
在HTML中还可以把图片划分成多个热点区域,每一个热点域链接到不同网页的资源.这种效果的实质是把一幅图片划分为不同的热点区域,再让不同的区域进行超链接.这就是影像地图.要完成地图区域超链接要用到三种标 ...
- java中遍历MAP,嵌套map的几种方法
java中遍历MAP的几种方法 Map<String,String> map=new HashMap<String,String>(); map.put("us ...
- arm-none-eabi-g++ -Xlinker -T "../LF3Kmonitor.ld" -Xlinker -Map="Bogota_ICT_V.map"-ram-hosted.ld -mc
1.arm-none-eabi-g++:是编译ARM裸板用的编译器,不依赖于操作系统. 2.-Xlinker -T "../LF3Kmonitor.ld" -Xlinker -Ma ...
- Map接口----Map中嵌套Map
package cn.good.com; import java.util.HashMap; import java.util.Iterator; import java.util.Map; impo ...
- 03-封装BeanUtil工具类(javabean转map和map转javabean对象)
package com.oa.test; import java.beans.BeanInfo; import java.beans.IntrospectionException; import ja ...
随机推荐
- laravel使用创建的request作为表单验证类
1.使用命令行工具创建request php artisan make request:validateLoginRequest 2.创建后进入app/Http/Requests目录下找到创建的文件 ...
- 【摸鱼向】UE4的AI模块探索手记(1)
前言 之前实现了自主创作的角色导入进UE4并成功控制其进行一系列动作,但目前的样子距离基本的游戏架构还差了一个很大的模块:NPC,而这部分是由电脑来进行自动控制,所以,我有一句话不知当讲不当讲(对,我 ...
- python 面向对象反射以及内置方法
一.反射 什么是反射:可以用字符串的方式去访问对象的属性,调用对象的方法(但是不能去访问方法),python中一切皆对象,都可以使用放射. 反射的四种方法: hasattr:hasattr(objec ...
- Linux网络安全篇,进入SELinux的世界(四)
SELinux的策略与规则管理set 1.安装SELInux工具 yum install setools-console 2.基本的命令 seinfo [-Atrub] -A ===> 列出SE ...
- Python常见数据结构-Dictionary字典
字典基本特点 字典的每个键值 key=>value 对用冒号 : 分割,每个键值对之间用逗号 , 分割,整个字典包括在花括号 {} 中. 键是唯一的,如果重复最后的一个键值对会替换前面的,值不需 ...
- MYSQ创建联合索引,字段的先后顺序,对查询的影响分析
MYSQ创建联合索引,字段的先后顺序,对查询的影响分析 前言 最左匹配原则 为什么会有最左前缀呢? 联合索引的存储结构 联合索引字段的先后顺序 b+树可以存储的数据条数 总结 参考 MYSQ创建联合索 ...
- CSS盒模型属性详细介绍
一.概述 CSS盒模型是定义元素周围的间隔.尺寸.外边距.边框以及文本内容和边框之间内边距的一组属性的集合. 示例代码: <!DOCTYPE html> <html lang=&qu ...
- 如何初学python?资深程序员浅谈,教你学会入门python
我认为python应该是现在市面上最简单,也是最值钱的一门编程语言,所以学习的人是越来越多,但是,如何初学python?这个问题困扰着很多初学python的人,今天,给大家简单聊聊这个话题. 我曾经也 ...
- HTTPS工作流程
HTTPS工作流程 RSA算法 RSA的密钥分成两个部分: PublicKey 加密数据 验证签名 不能解密 任何人都可以获得 Private Key 数据签名(摘要算法) 解密 加密(不用此功能) ...
- 王者荣耀英雄全皮肤4K高清大图,python爬虫帮你保存下来
前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. PS:如有需要Python学习资料的小伙伴可以加点击下方链接自行获取t.cn ...