UVa156 Ananagrams(映射map)
Ananagrams
题目
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 map
主要用到了vector和map,但还是很不熟练,今后还需要多做练习,反复琢摩。
#include<iostream>
#include<string>
#include<cctype>
#include<vector>
#include<map>
#include<algorithm>
using namespace std; map<string,int> cnt;
vector<string> words; //将单词s标准化
string repr(const string&s){
string ans=s;
for(int i=;i<ans.length();i++)
ans[i]=tolower(ans[i]);
sort(ans.begin(),ans.end());
return ans;
} int main(){
int n=;
string s;
while(cin>>s){
if(s[]=='#') break;
words.push_back(s);
string r=repr(s);
if(!cnt.count(r)) cnt[r]=;
cnt[r]++;
}
vector<string> ans;
for(int i=;i<words.size();i++)
if(cnt[repr(words[i])]==) ans.push_back(words[i]);
sort(ans.begin(),ans.end());
for(int i=;i<ans.size();i++)
cout<<ans[i]<<"\n";
return ;
}
UVa156 Ananagrams(映射map)的更多相关文章
- VIM键盘映射 (Map)~转载
VIM键盘映射 (Map) 设置键盘映射 使用:map命令,可以将键盘上的某个按键与Vim的命令绑定起来.例如使用以下命令,可以通过F5键将单词用花括号括起来: :map <F5> i{e ...
- 图像映射map
<map>标签:带有可点击区域的图像映射 定义一个客户端图像映射.图像映射(image-map)指带有可点击区域的一幅图像. 效果图: 点击相应蓝色标签可进入详情页面浏览. 代码: < ...
- <顶>vim快捷键映射Map使用
问题描述: 使用vim中的快捷键映射map,可以自定义快捷键 问题解决: (1)vim模式 (2)map前缀 (3)删除映射Map (4)使用示例 (5)查看快捷键映射 命令行---:verbose ...
- java映射(map用法)
主要分两个接口:collection和Map 主要分三类:集合(set).列表(List).映射(Map)1.集合:没有重复对象,没有特定排序方式2.列表:对象按索引位置排序,可以有重复对象3.映射: ...
- JAVA核心技术I---JAVA基础知识(映射Map)
一:映射Map分类 二:Hashtable(同步,慢,数据量小) –K-V对,K和V都不允许为null –同步,多线程安全 –无序的 –适合小数据量 –主要方法:clear, contains/con ...
- Hibernate映射Map属性2
Hibernate在映射Map属性时生成映射文件.需要注意的一些地方.下面是我的一个例子. Java类如下 public class NameAndNumber { private Integer i ...
- Hibernate映射Map属性
看到一篇Hibernate 映射Map属性的文章挺好的转载一下原地址:http://blog.sina.com.cn/s/blog_86f4502c0101fs1x.html Map集合属于有序集合, ...
- 元组Tuple、数组Array、映射Map
一.元组Tuple 元组Tuple是不同类型的值的聚集,元组的值将单个的值包含在圆括号中来构成,元组可以包含一个不同类型的元素 如 val riple = (100, "Scala" ...
- (ACM模板)映射map
#include<iostream> #include<cstdio> #include<map> using namespace std; int main() ...
随机推荐
- [官网] 一个很好的 search rpm 或者是deb 包的网站
https://pkgs.org Home About About pkgs.org - Packages Search The pkgs.org is created to provide you ...
- C# Excel 中设置文字对齐方式、方向和换行
在Excel表格中输入文字时,我们常常需要调整文字对齐方式或者对文字进行换行.本文将介绍如何通过编程的方式设置文字对齐方式,改变文字方向以及对文字进行换行. //创建Workbook对象 Workbo ...
- GitHub 将源代码保存在北极洞穴,至少使用 1000 年!
最近,GitHub分享了开放Arctic Code Vault的计划,该计划旨在存储和保存Flutter和TensorFlow等开源软件. 所有开放源代码项目的代码都将存储在胶片上,该胶片每帧包含88 ...
- 从入门到自闭之Python集合,深浅拷贝(大坑)
小数据池 int: -5~256 str: 字母,数字长度任意符合驻留机制 字符串进行乘法时总长度不能超过20 特殊符号进行乘法时只能乘以0 代码块: 一个py文件,一个函数,一个模块,终端中的每一行 ...
- java——ArrayList中remove()方法疑问总结
其实remove方法和contains方法大同小异,它的原理和contains方法相同https://www.cnblogs.com/lyxcode/p/9453213.html在这篇博客里面有详细说 ...
- C# 定义热键
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- CentOS/RHEL 安装EPEL第三方软件源
EPEL源简介 EPEL(Extra Packages for Enterprise Linux) 是由 FedORA 社区打造,为 RHEL 及衍生发行版如 CentOS等提供高质量软件包的项目.装 ...
- 记 Win10 - Archlinux - Archlinux(Emergency) 三系统安装/配置注意事项
起因是正常使用的archlinux做滚动更新,结果貌似有一个盘块写坏了(?). 手上没有U盘,进入不了linux,不好做fsck.于是直接就直接用win10了. 取消Fast Boot 当晚进入lin ...
- vue事件处理机制
<button @click="handleAdd1()">add1</button> <button @click="handleAdd2 ...
- js小功能1:全选全不选
<form> 请选择你爱好:<br> <input type="checkbox" name="hobby" id="h ...