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. ZOJ Problem Set - 1006

    注意:A的ascii为65,a为97就行了 其他没什么,略过. 代码参看: http://my.oschina.net/dianpaopao/blog/124545

  2. 项目使用Hbase进行数据快速查询的代码案例

    之前项目中对于数据详情的查询使用的ddb技术,由于成本过高,现考虑使用开源的hbase框架,借此机会进行hbase的代码案例记录,之前已经对 hbase的原理进行介绍,介绍了hbase中的rowkey ...

  3. DRF url控制 解析器 响应器 版本控制 分页(常规分页,偏移分页,cursor游标分页)

    url控制 第二种写法(只要继承了ViewSetMixin) url(r'^pub/$',views.Pub.as_view({'get':'list','post':'create'})), #获取 ...

  4. python — 进程

    目录 1. 进程 1.进程就是一个运行中的程序(是对正在运行程序的一个抽象). 2.程序和进程之间的区别: 程序只是一个文件 进程是这个文件被CPU运行起来了 程序是永久的,进程是暂时的. 3.进程- ...

  5. 怎样修改输入框 placehoder 提示文本的颜色?

    1. 在这个问题上, 不同浏览器的设置方法有所差异, 可以写成下面这种形式. ::-webkit-input-placeholder { /* WebKit browsers */ color: #9 ...

  6. kali入侵服务器的那一套实战

    dnsenum  -enum       xxxxx.com 枚举出网站的所有域名和服务器的ip地址 打开百度查询ip地址的所在地 whatweb xxxx.com 查看那些网站入口可以访问   以状 ...

  7. js之常用正则

    //用户名正则,4到16位(字母,数字,下划线,减号) let uPattern = /^[a-zA-Z0-9_-]{4,16}$/; //密码强度正则,最少6位,包括至少1个大写字母,1个小写字母, ...

  8. 在javascript中:(函数()()是一个匿名函数

    在javascript中:(函数()()是一个匿名函数,它主要使用函数中的变量范围来避免全局变量,影响整个页面环境,并提高代码兼容性. (函数())是标准函数定义,但不会复制到任何变量.所以有一个没有 ...

  9. Django基础第三篇

    一.ORM操作 1.常用字段和参数 Autofied 自增的整形字段,必填参数primary_key=True,  则成为数据库的主键,如无该字段,django自动创建 IntegerField 一个 ...

  10. Java ArrayList常用接口介绍及示例

    Java List 常用类型 类型 特征 ArrayList 随机访问元素快:中间插入与删除元素较慢:操作不是线程安全的 LinkedList 中间插入与删除操作代价较低,提供优化的顺序访问:随机访问 ...