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中 ...
随机推荐
- rootkit 内核函数hook
转自:https://0x90syntax.wordpress.com/2016/02/21/suterusu-rootkitx86%e4%b8%8earm%e7%9a%84%e5%86%85%e8% ...
- Dom4J读写xml
解析读取XML public static void main(String[] args) { //1获取SaxReader对象 SAXReader reader=new SAXReader(); ...
- (1) python--numpy
废话不多说,直接上代码 import numpy as np # 如何创建一个数组 arr = np.array([1, 2, 3, 4]) print(arr) # [1 2 3 4] # 查看数组 ...
- Android 各种功能代码收集
1.分享图片等文件到单个指定微信好友 /** * 分享信息到朋友 * * @param file * 假如图片的路径为path,那么file = new File(path); */ private ...
- c++类的隐藏,覆盖和重载,using关键字使用
转载一篇文章: http://www.cnblogs.com/ustc11wj/archive/2012/08/11/2637316.html 类的隐藏和重载不一样 类的隐藏是指 一个类继承自另外一个 ...
- AC日记——玻璃切割 51nod 1562
玻璃切割 思路: 并查集: 离线操作: 先把每次切割都存下来: 然后从后面不断合并切割: 然后每次更新最大长和宽: 记录答案: 要开longlong: 来,上代码 #include <cstdi ...
- (6)C#方法,作用域,方法重载
1.方法 返回类型 方法名(参数列表) 例如:int a(int b,int c) { 方法体 return b+c; } 函数如果有返回类型则最后要用return一个和返回类型一样的数据. 2.无返 ...
- codeforces-723D
题目连接:http://codeforces.com/contest/723/problem/D D. Lakes in Berland time limit per test 2 seconds m ...
- 二分LIS模板
假设存在一个序列d[1..9] = 2 1 5 3 6 4 8 9 7,可以看出来它的LIS长度为5. 下面一步一步试着找出它. 我们定义一个序列B,然后令 i = 1 to 9 逐个考察这个序列. ...
- Codeforces 871D Paths (欧拉函数 + 结论)
题目链接 Round #440 Div 1 Problem D 题意 把每个数看成一个点,如果$gcd(x, y) \neq 1$,则在$x$和$y$之间连一条长度为$1$的无向边. ...