Ananagrams

 Descriptions:

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
Input

题目链接:

https://vjudge.net/problem/UVA-156

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

因为不知道有多少个单词,就先用vector存起来,先全部转小写,按照字典顺序进行排序,然后用map存放这些处理过的单词,记录每个单词有多少个,然后数量为1的就是我们要找的单词,因为不重复且按照字典顺序,那么set是肯定要用的,存放最终答案,最后遍历set即可。

AC代码

#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define mod 1000000007
#define ll long long
#define INF 0x3f3f3f3f
#define ME0(x) memset(x,0,sizeof(x))
using namespace std;
map<string,int>words;//存放处理后的单词
vector<string> v;//存放初始单词
string s;
string stand(string r)//转小写,按照字典顺序排序
{
string ans=r;
int len=ans.length();
for(int i=;i<len;i++)
ans[i]=towlower(ans[i]);
sort(ans.begin(),ans.end());
return ans;
}
int main()
{
while(cin>>s,s!="#")
{
v.push_back(s);
string r=stand(s);
if(!words.count(r))//查询是否存在过
words[r]=;
words[r]++;//这个单词出现一次加一次
}
set<string> ans;
set<string>::iterator it;
for(int i=; i<v.size(); i++)
{
if(words[stand(v[i])]==)//出现一次的存入set,就是最后答案
ans.insert(v[i]);
}
for(it=ans.begin();it!=ans.end();it++)//遍历set,输出
cout<<*it<<endl;
}

最新文章

  1. hibernate学习-HibernateDemo
  2. Archlinux安装MySQL5.7.14压缩包版
  3. LintCode Two Strings Are Anagrams
  4. Android学习笔记(五)
  5. 模块化InnoSetup依赖项安装
  6. functional cohesion
  7. java笔试题整理
  8. Dockerfile制作sshd镜像
  9. ACM做题过程中的一些小技巧
  10. Uploadify 3.2上传文件,限制类型,大小,传递参数等
  11. pandas读取各类sql数据源
  12. Vue.js依赖收集
  13. Myeclipse修改设置Default VM Arguments
  14. 【XSY2760】nonintersect 计算几何
  15. python3.5opencv3图像文字标注
  16. Unity5天空盒小黑点问题
  17. 设置ListView显示到最后一行
  18. Centos6.5下rsync+inotify的配置详解
  19. Java的数组和list升序,降序,逆序函数Collections.sort和Arrays.sort的使用
  20. 84.Largest Rectangle in histogram---stack

热门文章

  1. 【BZOJ1110】[POI2007]砝码Odw 贪心
  2. Two-Factor Authentication 2FA
  3. linux环境下安装的activemq的输出日志
  4. delphi2010\delphi XE7 开发及调试WebService 实例
  5. CSS3学习笔记(4)—上下滑动展开的按钮
  6. Nginx中的惊群现象解决方法
  7. “cannot be resolved to a type” 错误解决方法
  8. Java中锁的内存语义
  9. C# GDI生成清晰【高质量】图片
  10. ACM应该学什么(知乎学长)