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)的更多相关文章

  1. VIM键盘映射 (Map)~转载

    VIM键盘映射 (Map) 设置键盘映射 使用:map命令,可以将键盘上的某个按键与Vim的命令绑定起来.例如使用以下命令,可以通过F5键将单词用花括号括起来: :map <F5> i{e ...

  2. 图像映射map

    <map>标签:带有可点击区域的图像映射 定义一个客户端图像映射.图像映射(image-map)指带有可点击区域的一幅图像. 效果图: 点击相应蓝色标签可进入详情页面浏览. 代码: < ...

  3. <顶>vim快捷键映射Map使用

    问题描述: 使用vim中的快捷键映射map,可以自定义快捷键 问题解决: (1)vim模式 (2)map前缀 (3)删除映射Map (4)使用示例 (5)查看快捷键映射 命令行---:verbose ...

  4. java映射(map用法)

    主要分两个接口:collection和Map 主要分三类:集合(set).列表(List).映射(Map)1.集合:没有重复对象,没有特定排序方式2.列表:对象按索引位置排序,可以有重复对象3.映射: ...

  5. JAVA核心技术I---JAVA基础知识(映射Map)

    一:映射Map分类 二:Hashtable(同步,慢,数据量小) –K-V对,K和V都不允许为null –同步,多线程安全 –无序的 –适合小数据量 –主要方法:clear, contains/con ...

  6. Hibernate映射Map属性2

    Hibernate在映射Map属性时生成映射文件.需要注意的一些地方.下面是我的一个例子. Java类如下 public class NameAndNumber { private Integer i ...

  7. Hibernate映射Map属性

    看到一篇Hibernate 映射Map属性的文章挺好的转载一下原地址:http://blog.sina.com.cn/s/blog_86f4502c0101fs1x.html Map集合属于有序集合, ...

  8. 元组Tuple、数组Array、映射Map

    一.元组Tuple 元组Tuple是不同类型的值的聚集,元组的值将单个的值包含在圆括号中来构成,元组可以包含一个不同类型的元素 如 val riple = (100, "Scala" ...

  9. (ACM模板)映射map

    #include<iostream> #include<cstdio> #include<map> using namespace std; int main() ...

随机推荐

  1. 【计算机】hosts设置

    2015 Google hosts 持续更新[更新于:2016-02-12] 老D 9个月前 (06-23) hosts 248,284  暂无评论 12798 文章目录[ 隐藏 ] 修改hosts的 ...

  2. eclipse 如何从Gitee.com克隆工程到本地,并运行

    1.再项目资源管理器里选择导入,导入 2.在导入向导中选择Git,选择来自Git的项目 3.选克隆URL 4.输入URL 和用户密码,点击下一步 4.下一步 5.选择保存路径 6.选择下一步,自动导入 ...

  3. #import "msado15.dll" no_namespace rename("EOF","adoEOF")

    引入动态链接库msado15.dll的信息, no_namespace--无命名空间 rename(“EOF”,“adoEOF”)--把文件结束符“EOF”,更换成“adoEOF”

  4. Thinkphp5 自定义上传文件名

    这几天在做tp5的上传文件模块,项目需求是要把文件名在上传之后修改为 用户名+原文件名的组合形式,在网上找了一会儿发现好像没有类似的文章...只好自己去研究研究了. 之前查看过看云上面的官方手册,文件 ...

  5. LeetCode 160——相交链表(JAVA)

    编写一个程序,找到两个单链表相交的起始节点. 如下面的两个链表: 在节点 c1 开始相交. 示例 1: 输入:intersectVal = 8, listA = [4,1,8,4,5], listB ...

  6. TIPTOP之分割split函数方法、getIndexOf、subString、replace、临时表创建;

    范例(cnmq001): 原:每次查询都把数据全部查询到临时表后再筛选: 现:查询到临时表的时候,增加可行的筛选条件,再二次筛选临时表的数据,进行优化: 1)临时表创建: PRIVATE FUNCTI ...

  7. CentOS7-部署kubernetes

    1 环境准备   节点 主机名 IP OS Master     k8s-master        192.168.57.1       centos 7        Node1  k8s-nod ...

  8. 修改hosts文件 解决coursera可以登录但无法播放视频的问题

    我们经常为了学习或者了解一些领域的知识为访问国外的网站,但是在国内,很多优秀的网站都被封锁了.在GFW(墙)的几种封锁方式中,有一种就是DNS污染,GFW会对域名解析过程进行干扰,使得某些被干扰的域名 ...

  9. java lesson13Homework

    /** * 1. 字符串解析,现有字符串,“卡巴斯基#杀毒软件#免费版#俄罗斯#”,解析出每个元素. */ package String13Practice; public class String0 ...

  10. unity 3D循环滚动效果

    https://blog.csdn.net/qinyuanpei/article/details/52765356 https://blog.csdn.net/chongzi_daima/articl ...