Description

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
解题思路:题目的意思就是找出唯一的(不与其他字符串串内重排后相同的)字符串,将它们排序并输出。做法:用map记录所有字符串内部字符(所有大写改成小写。为什么呢?上面的红色部分就已经解释了,我们需要统一换成大写或者小写)重排后的字符串的个数,用两个vector,一个用来保存文本中的所有单词,另一个保存出现次数为1的单词,最后排序输出即可。
AC代码:
 #include<bits/stdtr1c++.h>
using namespace std;
string repeat(string tmp){
for(size_t i=;i<tmp.size();++i)
if(isupper(tmp[i]))tmp[i]+=;//如果是大写字母,全部改为小写字母
sort(tmp.begin(),tmp.end());//串内重新排序
return tmp;
}
int main(){
string str,tp;
vector<string> vec,vrc;
map<string,int> mp;//记录串内字符重排后出现的次数
while(cin>>str&&str!="#"){
vec.push_back(str);
tp=repeat(str);
if(!mp.count(tp))mp[tp]=;//如果还没有出现,次数先初始化为0
mp[tp]++;//统计相同字符串出现的次数
}
vrc.clear();//清空容器
for(size_t i=;i<vec.size();++i)
if(mp[repeat(vec[i])]==)vrc.push_back(vec[i]);//如果该单词出现的次数为1,则满足条件,保存在vrc容器中
sort(vrc.begin(),vrc.end());//排序
for(size_t i=;i<vrc.size();++i)
cout<<vrc[i]<<endl;
return ;
}

J - Ananagrams(map+vector)的更多相关文章

  1. 2018.09.26 洛谷P2464 [SDOI2008]郁闷的小J(map+vector)

    传送门 本来出题人出出来想考数据结构的. 但是我们拥有map+vector/set这样优秀的STL,因此直接用map离散化,vector存下标在里面二分找答案就行了. 代码: #include< ...

  2. 【PTA 天梯赛训练】词频统计(map+vector)

    请编写程序,对一段英文文本,统计其中所有不同单词的个数,以及词频最大的前10%的单词. 所谓“单词”,是指由不超过80个单词字符组成的连续字符串,但长度超过15的单词将只截取保留前15个单词字符.而合 ...

  3. Educational Codeforces Round 11——A. Co-prime Array(map+vector)

    A. Co-prime Array time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  4. Sicily 1299 Academy Awards (map + vector)集装箱

    链接:http://soj.me/show_problem.php?pid=1299&cid= Description Selected from 3,850 teams from 1,329 ...

  5. 斗地主的综合案例实现(Map有序)

    斗地主的综合案例实现(Map有序) 整体思路 代码实现 import java.util.ArrayList; import java.util.Collections; import java.ut ...

  6. 分布式基础学习(2)分布式计算系统(Map/Reduce)

    二. 分布式计算(Map/Reduce) 分 布式式计算,同样是一个宽泛的概念,在这里,它狭义的指代,按Google Map/Reduce框架所设计的分布式框架.在Hadoop中,分布式文件 系统,很 ...

  7. 分布式基础学习【二】 —— 分布式计算系统(Map/Reduce)

    二. 分布式计算(Map/Reduce) 分布式式计算,同样是一个宽泛的概念,在这里,它狭义的指代,按Google Map/Reduce框架所设计的分布式框架.在Hadoop中,分布式文件系统,很大程 ...

  8. IntelliJ IDEA中,mybatis的配置文件(map.xml)无法编译到class文件夹下

    编译工具:IntelliJ IDEA 项目结构:maven 项目框架:SSM 问题:java目录下,mybatis的配置文件(map.xml)无法编译到class文件夹下 问题原因:在idea中,直接 ...

  9. STL——容器(Map & multimap)的插入与迭代器

    1. 容器(Map & multimap)的插入 map.insert(...);    //往容器插入元素,返回pair<iterator,bool> map中插入元素的四种方式 ...

随机推荐

  1. HDU 5641 King's Phone【模拟】

    题意: 给定一串密码, 判断是否合法. 长度不小于4 不能重复经过任何点 不能跳过中间点,除非中间点已经经过一次. 分析: 3*3直接记录出可能出现在两点之间的点,直接模拟就好. 注意审题,别漏了判断 ...

  2. SQL Server Management Studio自定义快捷键

    SQL Server Management Studio支持自定义快捷键:工具->选项->键盘: 其中,Alt+F1.Ctrl+1.Ctrl+2是系统预定义的快捷键. 双击表名(或按Ctr ...

  3. 用ReentrantLock和Condition实现生产者和消费者模式

    前面一篇文章<wait.notify应用场景(生产者-消费者模式)>是一种生产者消费者模式实现,今晚这是Lock方式实现,下面是源码: 生产者代码: /** * 生产者 * * @auth ...

  4. 思科CISCO 交换机命名规则

      思科交换机的命名规则要比路由的命名规则复杂, 看下这些:WS-C2960-24TC-L .WS-C2950G-24-EI-DC .WS-C2960-24TT-L .WS-C3750G-24TS-E ...

  5. [转]一个完整的Installshield安装程序实例

    @import url("http://files.cnblogs.com/files/go-jzg/vs.css"); --> Installshield安装程序实例—基本 ...

  6. [php learn] php 从头開始学习1

    前言:大概在2006年的时候,学习过一段时间的php.而且当时做了一个下载的站点,后来因为读研究生阶段用的是java.j2ee相关,所以php就搁浅掉了,php这些年也发生了非常大的变化,最大一个变化 ...

  7. nginx负载均衡向后台传递參数方法(后端也是nginxserver)

    做了一个站点是用nginx 做的负载均衡.后端也是多个nginxserver 遇到了一个问题.当做SSL支持时 前端nginx分发到 后端nginx后就成 http形式了(这样后台php用$_SERV ...

  8. Map-produce算法两个开源实现

    https://github.com/michaelfairley/mincemeatpy https://github.com/denghongcai/mincemeat-node

  9. redis集群状态信息维护脚本

    近期在做redis相关的东西.须要把2台redis切分成16个shard. 16个主shard分布在4台128G的机器上,从shard分布在12台64G的机器上.因为机器太多,查询相关的信息不太方便. ...

  10. Linux下Gcc 的编译过程

    在linux下开发难免会用到gcc编译.GCC(GNU Compiler Collection.GNU编译器套装),是由 GNU 开发的编程语言编译器.它是GNU编译器套装以GPL许可证所发行的自由软 ...