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;
}

【UVA - 156 】Ananagrams (set,map,vector)的更多相关文章

  1. 【uva 10048】Audiophobia(图论--Floyd算法)

    题意:有一个N点M边的无向带权图,边权表示路径上的噪声值.有Q个询问,输出 x,y 两点间的最大噪声值最小的路径的该值.(N≤100,M≤1000,Q≤10000) 解法:N值小,且问多对点之间的路径 ...

  2. 【面向对象版】HashMap(增删改查)

    前言: 关于什么是HashMap,HashMap可以用来做些什么,这些定义类的描述,请参照[简易版]HashMap(增删改查)的内容. 这章节主要是面向实例,直接进行HashMap(增删改查)的演示. ...

  3. 【uva 1658】Admiral(图论--网络流 最小费用最大流)

    题意:有个N个点M个边的有向加权图,求1~N的两条不相交路径(除了起点和终点外没有公共点),使得权和最小. 解法:不相交?也就是一个点只能经过一次,也就是我后面博文会讲的"结点容量问题&qu ...

  4. 【简易版】HashMap(增删改查)

    1.HashMap概述 (1)首先HashMap是基于哈希表的Map接口实现的.另外HashMap中存储的数据是按照键值跟键值对的关系来进行存储的. (2)不同于ArrayList方法的是,Array ...

  5. 【UVALive - 3487】 Duopoly(网络流-最小割)

    Description The mobile network market in country XYZ used to be dominated by two large corporations, ...

  6. 【NOIP模拟】Grid(字符串哈希)

    题目背景 SOURCE:NOIP2016-RZZ-1 T3 题目描述 有一个 2×N 的矩阵,矩阵的每个位置上都是一个英文小写字符. 现在需要从某一个位置开始,每次可以移动到一个没有到过的相邻位置,即 ...

  7. 【NOIP模拟】roads(最短路径转最小生成树)

    题目背景 SOURCE:NOIP2016-RZZ-1 题目描述 有 N 个城市,这些城市通过 M 条无向边互相连通,每条边有一个权值 Ci ,表示这条边的长度为 2^(Ci) ,没有两条边的长度是相同 ...

  8. 【BZOJ 2288】 2288: 【POJ Challenge】生日礼物 (贪心+优先队列+双向链表)

    2288: [POJ Challenge]生日礼物 Description ftiasch 18岁生日的时候,lqp18_31给她看了一个神奇的序列 A1, A2, ..., AN. 她被允许选择不超 ...

  9. 【详解】JNI(Java Native Interface)(一)

    前言: 一提到JNI,多数编程者会下意识地感受到一种无法言喻的恐惧.它给人的第一感觉就是"难",因为它不是单纯地在JVM环境内操作Java代码,而是跳出虚拟机与其他编程语言进行交互 ...

随机推荐

  1. 九度OJ 1134:密码翻译 (翻译)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:1988 解决:810 题目描述: 在情报传递过程中,为了防止情报被截获,往往需要对情报用一定的方式加密,简单的加密算法虽然不足以完全避免情报 ...

  2. 20170306 处理adobe flash player报错

    网页总是弹出Adobe Flash Player弹窗报错怎么办?打开网页时经常被Adobe Flash Player报错提示框困扰. 其实是因为系统安装了Debug版本的Flash Player,可是 ...

  3. ZOJ - 3956 Course Selection System 【01背包变形】

    题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3956 题意 给出N组Hi Ci 然后 要选出若干个 使得 这个式 ...

  4. Android wifi 从连接态自动断开的解决办法(dhcp导致)【转】

    本文转载自:http://blog.csdn.net/DKBDKBDKB/article/details/38490201 对wifi部分的代码流程已经看了段时间,前两天终于解决了工作中遇到的一个wi ...

  5. HDU4565 So Easy! —— 共轭构造、二阶递推数列、矩阵快速幂

    题目链接:https://vjudge.net/problem/HDU-4565 So Easy! Time Limit: 2000/1000 MS (Java/Others)    Memory L ...

  6. LightOJ1220 —— 质因数分解

    题目链接:https://vjudge.net/problem/LightOJ-1220 1220 - Mysterious Bacteria    PDF (English) Statistics ...

  7. 异步模式模式Future(结合Callable可以获取线程返回结果)

    submit 和 excute是有啥区别 如果有这样的需求: 多线程实现下载,提高效率. 不论是Thread类还是Runnable接口重写run方法,有个特点就是没有返回值~~~~~~ 我都主线程 如 ...

  8. the art of seo(chapter three)

    SEO Planning: Customizing Your Strategy ***Developing an SEO Plan Prior to Site Development***Determ ...

  9. slim.flatten——将输入扁平化但保留batch_size,假设第一维是batch

    slim.flatten(inputs,outputs_collections=None,scope=None) (注:import tensorflow.contrib.slim as slim) ...

  10. jmeter解压后启动jmeter.bat报错:Not able to find java executable or version

    错误详情: 错误解决方法: 修改环境变量配置将%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;移动到%SystemRoot%\system32;%SystemRoot%;%Sy ...