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



问题链接:UVA156 Ananagrams。

题意简述

  输入一个文本文件,从中提取出一些单词输出,输出的单词按照文本文件中的原来样子输出(字母大小写不变)。对于所有的单词,若字母不分大小写,单词经过重排顺序,与其他单词相同,这些单词则不在输出之列。

问题分析

  用C++语言编写程序,可以练习使用STL的功能。。另外一点,C++编写程序效率会更高。

程序说明

  使用了容器类map和vector。其他都是套路。

AC的C++语言程序如下:

/* UVA156 Ananagrams */#include <iostream>
#include <map>
#include <vector>
#include <algorithm>using namespace std;map<string, int> dict;
vector<string> words;
vector<string> ans;string getkey(const string& s)
{string key = s;for(int i = 0; i < (int)key.length(); i++)key[i] = tolower(key[i]);sort(key.begin(), key.end());return key;
}int main()
{string s;while(cin >> s && s[0] != '#') {string key = getkey(s);dict[key]++;words.push_back(s);}for(int i=0; i<(int)words.size(); i++)if(dict[getkey(words[i])] == 1)ans.push_back(words[i]);sort(ans.begin(), ans.end());for(int i=0; i<(int)ans.size(); i++)cout << ans[i] << "\n";return 0;
}

UVA156 Ananagrams【map+vector】相关推荐

  1. 【LeetCode】205. 同构字符串 【Map 双射】

    题目链接:https://leetcode-cn.com/problems/isomorphic-strings/ 题目描述 给定两个字符串 s 和 t,判断它们是否是同构的. 如果 s 中的字符可以 ...

  2. 【CF1230E】Kamil and Making a Stream【GCD性质】【暴力vector】

    传送门 题意:给一棵带点权的有根树,求所有满足uuu是vvv的祖先的路径(u,v)(u,v)(u,v)的路径上所有点权的gcdgcdgcd的和模1e9+71e9+71e9+7. N≤100000N \ ...

  3. UVA230 WF5169 POJ1886 Borrowers【map+set】

    Borrowers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 1621 Accepted: 389 Description ...

  4. [ACM]【map/分治】厦大月赛 环鸽的CHONG

    环鸽的CHONG 传送门 题意: 输入一个数列,如果该数列任意连续子序列满足存在一个数是唯一的(是"好序列"),输出chong,否则输出fuchong. 思路: 分治思想. 如果( ...

  5. 【GISER Painter】矢量切片(Vector tile)

    说明:本月的主要工作都是围绕制作矢量切片这一个核心问题进行的,所以2月的主题就以这个问题为主,目前分支出来的一些内容主要包括了TMS(Tile map service),OpenLayers3中的Pr ...

  6. 【重难点】【Java集合 02】Set、List、Map 的区别、常见的线程安全的集合类、Collection 为什么只能在 Iterator 中删除元素

    [重难点][Java集合 02]List.Set.Map 的区别.常见的线程安全的集合类.Collection 为什么只能在 Iterator 中删除元素 文章目录 [重难点][Java集合 02]L ...

  7. 统计公司员工喜欢吃的水果,并打印出最喜欢吃的前K中水果【map关联式容器,k/V结构】

    5.[附加题]– 本公司现在要给公司员工发波福利,在员工工作时间会提供大量的水果供员工补充营养. 由于水果种类比较多,但是却又不知道哪种水果比较受欢迎,然后公司就让每个员工报告了自己最爱吃的k种水果, ...

  8. 【论文阅读】GETNext: Trajectory Flow Map Enhanced Transformer for Next POI Recommendation

    [论文阅读]GETNext: Trajectory Flow Map Enhanced Transformer for Next POI Recommendation 前言 Next POI 推荐是根 ...

  9. 【C++】【第六篇-2】【黑马 p215~p242】【list容器】【set/multiset容器】【map/multimap容器】【函数对象】【谓词】【内建函数对象】

    [C++][第六篇-2][黑马 p215~p242][list容器][set/multiset容器][map/multimap容器][函数对象][谓词][内建函数对象] 3.7 list容器(p215 ...

最新文章

  1. tableau两个不同的图合并_Tableau可视化分析-业务常用图形绘制1
  2. pandas使用drop函数删除dataframe中指定索引列表对应位置的数据行(drop multiple rows in dataframe with integer index)
  3. Jquery常用方法合集,超实用
  4. 摆脱臃肿--Unity3D安卓包减肥秘笈
  5. 【java学习之路】(数据结构篇)001.数组
  6. React的单向数据流与组件间的沟通
  7. python builtins模块
  8. abaqus6.14安装教程 如何设置中文
  9. 不学点《近世代数》怎么学好现代密码学
  10. 谷歌街景15年乾坤大挪移!带你穿越法老的金字塔
  11. Java中 Tomcat 是干什么的?
  12. 2021年 阿里云商标注册申请的相关详情及分类介绍
  13. 外汇套利原理及策略EA
  14. 2020牛客多校九J-The Escape Plan of Groundhog
  15. 最近发现有很多人一直在问苹果ID双重认证怎么关闭。
  16. Java数据结构---hashMap
  17. InnoDB:page_cleaner:1000ms intended loop 解决
  18. 【Java菜鸟 04】Java中的File类详解
  19. BZOJ4399 魔法少女LJJ【线段树合并】【并查集】
  20. 12 第十二节课笔记(面向对象编程)

热门文章

  1. 计算机电容的作用,请问电脑cpu电容作用是什么?
  2. mysql中sql批量插入_sql中insert如何批量插入多条记录?
  3. 二、RabbitMQ常用交换器
  4. c语言创建json串,Jquery通过JSON字符串创建JSON对象
  5. 如何在html上做弹框效果,网页|利用提示框(Tooltip)实现弹窗效果
  6. html生成word附带图片_生成词云的几种方式对比
  7. Gstreamer——搭建RTSP服务器
  8. Windows驱动——利用WinDriver开发PCI设备驱动程序
  9. Tensorflow训练和预测中的BN层的坑(转载)
  10. java oracle thin_????java thin 连接oracle url的几种写法