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 aseries 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


解题心得

  1. 考察map和set应用的一道题,很简单,因为不区分大小写,所以可以先将string中的所有大写转换成小写,然后sort将string排个序,排好序的string映射一下。最后再重复找一遍就可以了。

#include<bits/stdc++.h>
using namespace std;
map<string,int> Map;
set <string> se2;
int main()
{
string s;
while(cin >> s)
{
if(s == "#")
break;
string s1 = s;
for(string::iterator iter = s1.begin();iter!=s1.end();iter++)
*iter = tolower(*iter);
sort(s1.begin(),s1.end());
Map[s1]++;//先将所有的string小写转换,排序,映射一下;
se2.insert(s);//记录本身的单词
} for(set<string> :: iterator iter=se2.begin();iter!=se2.end();iter++)
{
string k = *iter;
for(string::iterator iter1=k.begin();iter1!=k.end();iter1++)
*iter1 = tolower(*iter1);
sort(k.begin(),k.end());
if(Map[k] == 1)//单词只出现过一次即符合条件
cout<<*iter<<endl;
}
return 0;
}

map函数的应用:UVa156-Ananagrams的更多相关文章

  1. map 函数----filter函数

    # map 函数 l = (1,2,4,5,6,7,8,9,) print(list(map(lambda x:x**2,l)))#使用list类型((map函数(lambda 匿名函数定义x值:x* ...

  2. 实现python中的map函数

    假设Python没有提供map()函数,自行编写my_map()函数实现与map()相同的功能.以下代码在Python 2.7.8中实现. 实现代码: def my_map(fun,num): i = ...

  3. js parseInt和map函数

    今天看了一个js的题目["1","2","3"].map(parseInt),看到后脑海中浮现的答案是[1,2,3],但是看到正确答案后蒙了 ...

  4. JavaScript中map函数和filter的简单举例(转)

    js的数组迭代器函数map和filter,可以遍历数组时产生新的数组,和python的map函数很类似1)filter是满足条件的留下,是对原数组的过滤:2)map则是对原数组的加工,映射成一一映射的 ...

  5. Python-lambda函数,map函数,filter函数

    lambda函数主要理解: lambda 参数:操作(参数). lambda语句中,冒号前是参数,可以有多个,用逗号隔开,冒号右边的返回值.lambda语句构建的其实是一个函数对象 map函数: ma ...

  6. map() 函数

    map()函数 map()是 Python 内置的高阶函数,它接收一个函数 f 和一个 list,并通过把函数 f 依次作用在 list 的每个元素上,得到一个新的 list 并返回. 例如,对于li ...

  7. STL : map函数的运用 --- hdu 4941 : Magical Forest

    Magical Forest Time Limit: 24000/12000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Other ...

  8. Swift之map函数的强大之处

    CollectionType Map 在CollectionType的extension中map方法的定义: extension CollectionType { /// Return an `Arr ...

  9. python map函数

    map()函数 map()是 Python 内置的高阶函数,它接收一个函数 f 和一个 list,并通过把函数 f 依次作用在 list 的每个元素上,得到一个新的 list 并返回. 例如,对于li ...

  10. perl的map函数

    perl的map函数的使用: 语法 map EXPR, LIST map BLOCK LIST 定义和使用 对list中的每个元素执行EXPR或BLOCK,返回新的list.对每一此迭代,$_中保存了 ...

随机推荐

  1. 移动端 mui框架中input输入框或任何输入框聚焦后页面自动上移

    一.mui框架中点击input后,安卓手机弹出自带的输入键盘时,页面自动上移 实现方法: (1)只要把input标签放在mui-content这个类里面就可以了 <div class=" ...

  2. JS=和==和===的区别

    1. = : 赋值运算,赋值使用2.== :比较运算,仅比较自动转换后的值是否相等,忽略 变量类型,如:'1' == 1 //true 3.=== : 比较运算,比较值和变量类型是否相等,如:'1' ...

  3. AJPFX分享java排序之希尔排序

    (1)基本思想:算法先将要排序的一组数按某个增量d(n/2,n为要排序数的个数)分成若干组,每组中记录的下标相差d.对每组中全部元素进行直接插入排序,然后再用一个较小的增量(d/2)对它进行分组,在每 ...

  4. kafka系列一:单节点伪分布式集群搭建

    Kafka集群搭建分为单节点的伪分布式集群和多节点的分布式集群两种,首先来看一下单节点伪分布式集群安装.单节点伪分布式集群是指集群由一台ZooKeeper服务器和一台Kafka broker服务器组成 ...

  5. nconf修改密码

    修改nconf登录界面密码 [root@Cnyunwei config]# vi .file_accounts.php <?php/*## User/Password file for simp ...

  6. MYSQL 写入emoji表情字符处理

    这个鬼emoji表情是4个字节,mysql使用的utf8编码,UTF8占3个字节,要存储那个emoji表情需要将mysql编码由UFT8改为UFT8的超集,utf8mb4; 改数据库编码容易引起大面的 ...

  7. Servlet和JSP之标签文件学习

    在上一篇文章中介绍了自定义标签的用法,接下来介绍标签文件的用法啦. tag file指令 tag file简介 用tag file的方式,无需编写标签处理类和标签库描述文件,也可以自定义标签.tag ...

  8. roi_pooling层

    roi_pooling层先把rpn生成的roi映射到特征提取层最后一层,然后再分成7*7个bin进行池化 下面是roi_pooling层的映射到特征提取层的代码,可以看到用的是round函数,也就是说 ...

  9. 爬虫4_python2

    import urllib2 response = urllib2.urlopen("https://www.baidu.com") print response.read() 构 ...

  10. gson对象的相互转换

    参见 http://www.javacreed.com/gson-deserialiser-example/