题目连接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=92

13913904 156 Ananagrams Accepted C++ 0.009 2014-07-20 15:31:41

 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 <cstring>
#include <cstdlib>
#include <cctype>
#include <cstdio>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <map>
#include <vector>
using namespace std; map<string, int> cnt;
vector<string> words; string cal_index(const string& s) {
string ans = s;
for (int i = ; i < ans.size(); ++ i) {
ans[i] = tolower(ans[i]);
}
sort(ans.begin(), ans.end());
return ans;
} int main () {
string str;
while (cin >> str) {
if (str == "#") {
break;
}
words.push_back(str);
string sort_str = cal_index(str);
if (!cnt.count(sort_str)) {
cnt[sort_str] = ;
}
cnt[sort_str] ++;
} vector<string> ans;
for (int i = ; i < words.size(); ++ i) {
if (cnt[cal_index(words[i])] == ) {
ans.push_back(words[i]);
}
} sort(ans.begin(), ans.end());
for (int i = ; i < ans.size(); ++ i) {
cout << ans[i] << endl;
}
return ;
}
												

UVa156.Ananagrams的更多相关文章

  1. UVa156 Ananagrams(映射map)

    Ananagrams 题目 Most crossword puzzle fans are used to anagrams--groups of words with the same letters ...

  2. UVa-156 Ananagrams(map映射)

    #include <iostream> #include <algorithm> #include <cmath> #include <cstdio> ...

  3. UVa-156 Ananagrams 反片语【map】【vector】

    题目链接:https://vjudge.net/contest/211547#problem/D 题目大意: 输入一些单词,找出所有满足以下条件的单词:该单词不能通过字母重排,得到输入文本中的另外一些 ...

  4. uva-156(Ananagrams UVA - 156)

    map容器的模板题,判断是否能交换字母顺序变成另外一个单词,只需要先把单词都变成小写字母.然后再按字母字典序排序,放入map中进行计数,然后把计数为一的再放入另一个容器,再排序输出即可 我的代码(刘汝 ...

  5. 【UVA - 156 】Ananagrams (set,map,vector)

    Ananagrams  Descriptions: Most crossword puzzle fans are used to anagrams--groups of words with the ...

  6. ACM题目————STL练习之Ananagrams

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

  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 - Ananagrams (反片语)

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

  9. Winter-2-STL-F Ananagrams 解题报告及测试数据

    Time Limit:3000MS     Memory Limit:0KB  Description Most crossword puzzle fans are used to anagrams- ...

随机推荐

  1. virsh -c exs://ip/?no_verify=1 --readonly nodeinfo

  2. Django架设blog步骤

    @import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...

  3. 马士兵 Servlet_JSP(2) JSP源代码)

    1.最简单的JSP HelloWorld.jsp <html>     <head>         <title>Hello</title>     ...

  4. Java IO教程 导读

    Java IO是一套java 用来读写数据(输入和输出)的API.大部分程序都要处理一些输入,并有输入产生一些输出.Java为此提供了java.io包. 如果你浏览下java.io包,会对其中各样的类 ...

  5. 关于DevExpress的gridControl的简单使用

    数据绑定 首先生成table,然后更改列名,最后添加一个选择列,类型为"System.Boolean",这样在绑定上gridcontrol的时候会出现一列选择框 table.Col ...

  6. Redis安全

    安全 执行在可信环境 Redis的安全设计是在"Redis执行在可信环境"这个前提下做出的.在生产环境执行时不能同意外界直接连接到Redisserver上.而应该通过应用程序进行中 ...

  7. log4net使用具体解释

    说明:本程序演示怎样利用log4net记录程序日志信息.log4net是一个功能著名的开源日志记录组件.利用log4net能够方便地将日志信息记录到文件.控制台.Windows事件日志和数据库(包含M ...

  8. c++11 生产者/消费者

    下面是一个生产者消费者问题,来介绍condition_variable的用法.当线程间的共享数据发生变化的时候,可以通过condition_variable来通知其他的线程.消费者wait 直到生产者 ...

  9. C#使用checked关键字处理"溢出"错误

    代码如下: private void btnCalculate_Click(object sender, EventArgs e) { byte num1, num2;//定义两个byte变量 if( ...

  10. python查看删除你微信的账号

    #应用环境:python2.7 #!/usr/bin/env python # coding=utf-8 from __future__ import print_function import os ...