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

输入一些单词,找出所有满足如下条件的单词:该单词不能通过字母重排,得到输入文本中的另外一个单词。在判断是否满足条件时,字母不分大小写,但在输出时应保留输入中的大小写,按字典序进行排列(所有大写字母在所有小写字母的前面)。

#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <vector>using namespace std;
// 单词映射<单词,出现次数>
map<string, int> content;
// 单词容器
vector<string> words;// 将单词s进行标准化
string repr(const string s) {string ans = s;// 小写for(int i = 0; i < ans.length(); i++) {ans[i] = tolower(ans[i]);}// 重排sort(ans.begin(), ans.end());return ans;
}int main() {string s;while(cin >> s) {if(s[0] == '#') {break;}words.push_back(s);string r = repr(s);// 该单词不存在if(!content.count(r)) {content[r] = 0;}content[r]++;}// 答案vector<string> ans;for(int i = 0; i < words.size(); i++) {// 只出现一次if(content[repr(words[i])] == 1) {ans.push_back(words[i]);}}// 字典排序sort(ans.begin(), ans.end());vector<string>::iterator it;for(it = ans.begin(); it != ans.end(); it++) {cout << *it << endl;}return 0;
}

156 - Ananagrams相关推荐

  1. uva 156 Ananagrams

    题目大意: 输入一些单词,找出所有满足条件的单词,该单词不能通过重排,得到输入文本的另一个单词,在判断满足条件时,不区分大小写,但在输出时保留输入的大小写,按字典序排序 解体思路: 把所有单词保存,在 ...

  2. 很有趣的STL初学资料

    1.泛型程序设计简介与迭代器的介绍 2.常见的STL容器及其例题应用(UVA10474,UVA101,UVA10815,UVA156,UVA540,UVA136 HDU1027,CF501B,HDU1 ...

  3. π-Algorithmist分类题目(1)

    原题网站:Algorithmist,http://www.algorithmist.com/index.php/Main_Page π-Algorithmist分类题目(1) Sorting UVAL ...

  4. 算法竞赛入门经典(第2版)—第五章(C++与STL入门)

    文章目录 零碎知识点整理 题目 10474 - Where is the Marble? 101 - The Blocks Problem 10815 - Andy's First Dictionar ...

  5. 紫书《算法竞赛入门经典》

    紫书<算法竞赛入门经典>题目一览 第3章 数组和字符串(例题) UVA 272 TEX Quotes UVA 10082 WERTYU UVA 401 Palindromes UVA 34 ...

  6. 提取了下刘汝佳推荐的题号...

    今天闲来没事上uva oj提取了下刘汝佳推荐的acm题号,原始数据如下: Volume 0. Getting Started    10055 - Hashmat the Brave Warrior ...

  7. php7 xdebug 性能,PHP 7 Xdebug 深深的坑

    zend_extension 7.0 下的 php.ini 配置 [XDebug] ;; Only Zend OR (!) XDebug zend_extension=f:\xampp\php\ext ...

  8. Ananagrams(sort+map) UVA - 156 统计字谜

    Ananagrams(sort+map) UVA - 156 统计字谜 Most crossword puzzle fans are used to anagrams - groups of word ...

  9. Ananagrams Uva 156

    Ananagrams (map的使用) Most crossword puzzle fans are used to anagrams–groups of words with the same le ...

最新文章

  1. PHP哈希表碰撞攻击原理
  2. ORACLE 中dbms_stats的使用
  3. 征战蓝桥 —— 2013年第四届 —— C/C++A组第5题——前缀判断
  4. 如何使用fio模拟线上环境
  5. 作者:孙大为,男,博士后,中国地质大学(北京)信息工程学院讲师。
  6. mysql-cluster 安装篇(1)---简介
  7. 快压卸载后,右键打开压缩文件时还是有快压,方案:删除注册表相关项
  8. 通信upf是什么意思_管理UPF的方法、装置及系统与流程
  9. MATLAB中绘制椭圆
  10. Excel数据透视表怎么做
  11. 云原生安全构筑下一代企业安全架构
  12. python爬取qq音乐评论+jieba分词并统计词频+绘制词云并可视化数据
  13. CSS实现LOL皮肤简单3D翻牌效果
  14. 2021年中国企业风险投资发展现状及未来发展趋势分析[图]
  15. APP统计报表,这几个指标最有价值
  16. Python基础学习第七天
  17. RationalDMIS 2020 叶片检测 -快速定义叶片截面线方法
  18. IBM ITS中国区总经理鞠立老师讲女性的职业规划与发展
  19. 环境变量的作用及设置方法
  20. nvenc vs x264 对比(2)

热门文章

  1. android 存储方式简书,Android的多种数据存储方式
  2. WPF 圆型布局(测量过程)
  3. CentOS7 Cloudera Manager6 完全离线安装 CDH6 集群
  4. 【MySQL】rds 不支持镜像表/联合表,怎么办?
  5. 【Vue-Router】模拟源码,解析 Vue-Router 的实现原理
  6. js lottie 兼容 json、图片缓存问题、修改文字,图片
  7. Orace用户创建及权限分配
  8. Linux入门学习(八)
  9. python解析格式文件
  10. soa面向服务体系结构_服务和面向微服务的体系结构简介