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. Docker(二) Dockerfile 使用介绍

    前言 图解Docker 镜像.容器和 Dockerfile 的关系: 一.Dockerfile的概念 Docker 镜像是一个特殊的文件系统,除了提供容器运行时所需的程序.库.资源.配置等文件外,还包 ...

  2. 架构设计:"4+1"视图

    概念 "4+1"视图,是指从5个不同视角来描述软件体系结构. "4+1"分别指: 逻辑视图 过程视图 物理视图 开发视图 场景/用例 视图 逻辑架构的描述可以围 ...

  3. PHP 核心特性 - 匿名函数

    提出 在匿名函数出现之前,所有的函数都需要先命名才能使用 function increment($value) { return $value + 1; } array_map('increment' ...

  4. [Collection] 的常用方法有这些。

  5. 关于GC(中):Java垃圾回收相关基础知识

    Java内存模型 (图源: 深入理解JVM-内存模型(jmm)和GC) 区域名 英文名 访问权限 作用 备注 程序计数器 Program Counter Register 线程隔离 标记待取的下一条执 ...

  6. Linux网络配置文件

    centos为例: /etc/sysconfig/network文件 用于基本的网络配置信息,包含了控制和网络有关的文件和守护进程的行为参数,包括主机名.网关等 (默认:我的cent0s7在为空,fe ...

  7. LVM扩容案例

    LVM基础命令: pvdisplay 查看检查pv pvremove /dev/sdb #清除一个pv fdisk -l 检查磁盘 df -h 检查全部磁盘大小 df -Th 检查磁盘大小和分区格式类 ...

  8. 快速遍历OpenCV Mat图像数据的多种方法和性能分析 | opencv mat for loop

    本文首发于个人博客https://kezunlin.me/post/61d55ab4/,欢迎阅读! opencv mat for loop Series Part 1: compile opencv ...

  9. MySQL 支持 emoji 图标存储

    在MySLQ中 UPDATA 和 INSERT 数据的时候,如果数据上面带有emoji图标,例如:?.?.? 很容易更新或者插入不成功,导致报错. 1 2 Error: ER_TRUNCATED_WR ...

  10. Springboot操作Elasticsearch

    常见的日志系统是基于logstach+elasticsearch+kibna框架搭建的,但是有时候kibana的查询无法满足我们的要求,因此有时需要代码去操作es,本文后续都以es代替elastics ...