Most crossword puzzle fans are used to anagrams — groups of words with the same letters in differentorders — for example OPTS, SPOT, STOP, POTS and POST. Some words however do not have thisattribute, no matter how you rearrange their letters, you cannot
form another word. Such words arecalled ananagrams, an example is QUIZ.Obviously such definitions depend on the domain within which we are working; you might thinkthat ATHENE is an ananagram, whereas any chemist would quickly produce ETHANE. One possibledomain
would be the entire English language, but this could lead to some problems. One could restrictthe domain to, say, Music, in which case SCALE becomes a relative ananagram (LACES is not in thesame 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 relativeananagrams. 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.InputInput
will consist of a series of lines. No line will be more than 80 characters long, but may contain anynumber of words. Words consist of up to 20 upper and/or lower case letters, and will not be brokenacross lines. Spaces may appear freely around words, and at
least one space separates multiple wordson the same line. Note that words that contain the same letters but of differing case are considered tobe anagrams of each other, thus ‘tIeD’ and ‘EdiT’ are anagrams. The file will be terminated by a lineconsisting of
a single ‘#’.OutputOutput will consist of a series of lines. Each line will consist of a single word that is a relative ananagramin the input dictionary. Words must be output in lexicographic (case-sensitive) order. There will alwaysbe at least one relative
ananagram.Sample Inputladder came tape soon leader acme RIDE lone Dreis peatScAlE orb eye Rides dealer NotE derail LaCeS drIednoel dire Disk mace Rob dries#Sample OutputDiskNotEderaildrIedeyeladdersoon

题解:就是查找字母重组后出现一次的单词;先将单词变为小写并按字典序排列,用map容器存储单词,然后用其映射

表示出现其次数。最后将出现一次的单词保存到set中,将其输出。

AC代码为:

#include<iostream>

#include<string>

#include<sstream>

#include<vector>

#include<map>

#include<algorithm>

using namespace std;

map<string,int> s;

vector<string>words;

string tr(string &s)

{   string ss=s;

    for(int i=0;i<ss.length();i++)

    {

        ss[i]=tolower(ss[i]);

    }

    sort(ss.begin(),ss.end());

    return ss;

}

int main()

{

    string st;

    while(cin>>st)

    {

        if(st[0]=='#')break;

        string r=tr(st);

        words.push_back(st);

        if(s.count(r)==0)s[r]=1;

        else s[r]++;

    }

    vector<string>ans;

    for(int i=0;i<words.size();i++)

    {

        if(s[tr(words[i])]==1)ans.push_back(words[i]);

    }

    sort(ans.begin(),ans.end());

    for(int i=0;i<ans.size();i++)

    {

        cout<<ans[i]<<endl;

    }

    return 0;

}

UVA-156的更多相关文章

  1. uva 156 - Ananagrams (反片语)

    csdn:https://blog.csdn.net/su_cicada/article/details/86710107 例题5-4 反片语(Ananagrams,Uva 156) 输入一些单词,找 ...

  2. UVa 156 (映射 map)

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  3. UVA 156 Ananagrams (STL multimap & set)

    原题链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=98&p ...

  4. UVA 156 Ananagrams ---map

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

  5. UVa 156 Ananagrams

    题意:给出一些单词,在这些单词里面找出不能通过字母重排得到的单词(判断的时候不用管大小写),然后按照字典序输出. 学习的紫书的map= = 将每一个单词标准化 先都转化为小写,再排序(即满足了题目中说 ...

  6. uva 156 (map)

    暑假培训习题 1.用vector<string>储存string类型的输入单词: 2.将vector中的元素逐一标准化后映射进map中,并给map值加一: 3.新建一个空的vector 4 ...

  7. STL语法——映射:map 反片语(Ananagrams,UVa 156)

    Description Most crossword puzzle fans are used to anagrams--groups of words with the same letters i ...

  8. 反片语 UVA 156

    //该单词不能通过字母重排,得到输入文本中的另外一个单词.在判断是否满足条件时,字母部分大小写 #include<iostream> #include<vector> #inc ...

  9. UVA 156:Ananagrams (vector+map+sort)

    题意:一大堆单词中间有空格隔开,以'#'结束输出,问只出现一次的的单词有哪些(如果两个具有相同的长度,相同的字母也算是相同的,不区分大小写,如:noel和lone属于一个单词出现两次).最后按照字典序 ...

  10. UVA 156 (13.08.04)

     Ananagrams  Most crossword puzzle fans are used to anagrams--groupsof words with the same letters i ...

随机推荐

  1. 20190806-sed面试题

    由于比较难,附上PPT,没事还得看 下载:https://www.lanzous.com/i5cs9aj 密码:arka 1.删除centos7系统/etc/grub2.cfg⽂件中所有以空⽩开头的⾏ ...

  2. 分组取topN

    假设有这样一个文件,文件内容如下 class1 class2 class1 class1 class2 class2 class1 class2 class1 class2 要求按照班级分组取出每个班 ...

  3. ENS中文文档系列之一 [ ENS介绍 ]

    前言 ENS中文文档是由我照ENS英文官方文档翻译而来,其中的一些内容和细节得到了ENS官方团队的指导.文档中包含 “LBB译注” 的地方是译者为了便于读者理解而进行的注释. 未来一段时间,我会在该博 ...

  4. Java描述设计模式(21):状态模式

    本文源码:GitHub·点这里 || GitEE·点这里 一.生活场景 1.场景描述 变色龙是爬行动物,是非常奇特的动物,它有适于树栖生活的种种特征和行为,身体也会随着环境的变化而变化出适应环境的颜色 ...

  5. runlevel init

    init概念存在于cnetos7以下,配置文件/etc/inittab init 以及 文本和图形界面切换(可以用ctrl+alt+n 或者 init3 5切换,不是重启切) 命令init N 0 关 ...

  6. C# Json之序列化与反序列化

    前言:在实际开发过程中经常都要和Json打交道,序列化与反序列化就成了开发中必不可缺的技能.本篇博客就教大家如何进行Json序列化与反序列化. 首先要添加引用NuGet包,Newtonsoft.Jso ...

  7. Asis CTF 2016 b00ks理解

    ---恢复内容开始--- 最近在学习堆的off by one,其中遇到这道题,萌新的我弄了大半天才搞懂,网上的很多wp都不是特别详细,都得自己好好调试. 首先,这题目是一个常见的图书馆管理系统,虽然我 ...

  8. Amazon Lightsail部署LAMP应用程序之部署实验室基础架构

    一.在Lightsail中创建LAMP堆栈实例 1.在AWS管理控制台的"服务"下拉选项中单击"Lightsail". 2.在语言方面选择 "英语&q ...

  9. [从今天开始修炼数据结构]线性表及其实现以及实现有Itertor的ArrayList和LinkedList

    一.线性表 1,什么是线性表 线性表就是零个或多个数据元素的有限序列.线性表中的每个元素只能有零个或一个前驱元素,零个或一个后继元素.在较复杂的线性表中,一个数据元素可以由若干个数据项组成.比如牵手排 ...

  10. python 面向对象的基本概念(未完待续)

    面向对象编程简称OOP(Object-oriented-programming),是一种程序设计思想. 面向过程编程(如C语言)指一件事该怎么做,面向对象编程(如Java.python)指一件事该让谁 ...