UVa 156 Ananagrams(STL,map)
| Ananagrams |
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记下出现次数即可 仅仅出现过一次的就是要输出的
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cctype>
#include<map>
using namespace std;
typedef vector<string>::iterator it;
vector<string> ans;
map<string, int> cnt, tcnt;
map<string, string> ss;
int main()
{
string s, t;
while (cin >> s, s != "#")
{
t = s;
ans.push_back (s);
for (int j = 0; j < t.length(); ++j)
t[j] = tolower (t[j]);
sort (t.begin(), t.end());
ss[s] = t;
++cnt[t];
}
sort (ans.begin(), ans.end());
for (it i = ans.begin(); i < ans.end(); ++i)
if (cnt[ss[*i]] == 1) cout << *i << endl;
return 0;
}
UVa 156 Ananagrams(STL,map)的更多相关文章
- UVA 156 Ananagrams (STL multimap & set)
原题链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=98&p ...
- uva 156 - Ananagrams (反片语)
csdn:https://blog.csdn.net/su_cicada/article/details/86710107 例题5-4 反片语(Ananagrams,Uva 156) 输入一些单词,找 ...
- UVA 156 Ananagrams ---map
题目链接 题意:输入一些单词,找出所有满足如下条件的单词:该单词不能通过字母重排,得到输入文本中的另外一个单词.在判断是否满足条件时,字母不分大小写,但在输出时应保留输入中的大小写,按字典序进行排列( ...
- UVa 156 (映射 map)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVa 156 Ananagrams
题意:给出一些单词,在这些单词里面找出不能通过字母重排得到的单词(判断的时候不用管大小写),然后按照字典序输出. 学习的紫书的map= = 将每一个单词标准化 先都转化为小写,再排序(即满足了题目中说 ...
- stl::map之const函数访问
如何在const成员数中访问stl::map呢?例如如下代码: string ConfigFileManager::MapQueryItem(const string& name) const ...
- hdu4941 Magical Forest (stl map)
2014多校7最水的题 Magical Forest Magical Forest Time Limit: 24000/12000 MS (Java/Others) Memory Limit ...
- [CareerCup] 13.2 Compare Hash Table and STL Map 比较哈希表和Map
13.2 Compare and contrast a hash table and an STL map. How is a hash table implemented? If the numbe ...
- STL MAP及字典树在关键字统计中的性能分析
转载请注明出处:http://blog.csdn.net/mxway/article/details/21321541 在搜索引擎在通常会对关键字出现的次数进行统计,这篇文章分析下使用C++ STL中 ...
随机推荐
- keystone总结
1. Keystone(OpenStack Identity Service)是OpenStack框架中,负责身份验证.服务规则和服务令牌的功能, 它实现了OpenStack的Identity API ...
- LayoutInflater学习总结
----参考,转载,借用来源:http://blog.csdn.net/guolin_blog/article/details/12921889 Activity类中onCreate方法中,setCo ...
- Linux Context , Interrupts 和 Context Switching 说明【转】
转自:http://blog.csdn.net/tianlesoftware/article/details/6461207 一. 进程Context 定义 当一个进程在执行时, CPU的所有寄存器中 ...
- java应用挂死故障排查
现象: java开发的web应用无法访问 排查: 1.从resin/log/watchdog-manager.log的日志里可以看出来,jvm的内存满,无法创建新进程 java.lang.OutOfM ...
- HDU5487 Difference of Languages(BFS)
题意:给你两个自动机,求出最短的(如果有相同最短的则求出字典序最小的)能被其中一个自动机接收而不能被另外一个自动机接收的字符串. 一看是自动机以为是神题,后来比赛最后才有思路. 两个自动机的状态都是小 ...
- Weblogic 监控工具汇总及简介
https://blog.csdn.net/hualusiyu/article/details/39608637
- 谷歌浏览器cookies管理插件:EditThisCookie
目前大多数网站的登录程序或者是其他保存用户信息到本地浏览器的方式都是使用cookies的方式,而cookies虽然可以为用户的一些操作带来便捷,比如可以记住用户的密码或者用户的选择历史,在下一次操作的 ...
- codevs 2837 考前复习——01背包
时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 查看运行结果 题目描述 Description Aiden马上要考试了,可他还没怎么复习,于是他 ...
- JavaScript 函数调用的 this词法
函数调用时的this实际上是在函数被调用时发生绑定,它指向什么完全取决于函数在哪里被调用. 特例:当函数作为构造函数被调用时,即使用new 来构造一个新对象,会自动执行以下操作: [1]创建一个新对象 ...
- 深入JS正则先行断言
这里是 Mastering Lookahead and Lookbehind 文章的简单翻译,这篇文章是在自己搜索问题的时候stackoverflow上回答问题的人推荐的,看完觉得写得很不错.这里的简 ...