题目连接: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. 《Learn python the hard way》Exercise 48: Advanced User Input

    这几天有点时间,想学点Python基础,今天看到了<learn python the hard way>的 Ex48,这篇文章主要记录一些工具的安装,以及scan 函数的实现. 首先与Ex ...

  2. syslog_test.c 简单的syslog函数

    #cat syslog_test.c #include<stdio.h> #include<stdlib.h> #include<syslog.h> int mai ...

  3. [RxJS] Error Handling in RxJS

    Get your code back on the happy path! This lesson covers a variety of ways to handle exceptions thro ...

  4. Android Studio IDE 所遇问题汇总

    [窗体视图无法显示]     在/res/values/styles.xml文件中,修改一下内容 <!-- Base application theme. --><style nam ...

  5. _js day10

  6. MVC4过滤器(转)

    先来看看一个例子演示过滤器有什么用: public class AdminController : Controller { // ... instance variables and constru ...

  7. ashx ajax 与 自定义javascript函数

    1.getUserPower为自定义javascript函数 获取权限  (1).ashx 处理程序的相对地址(必须是相对地址)  (2).au 权限名称  (3).classname 类名  (4) ...

  8. POJ 1286 Necklace of Beads(项链的珠子)

    Necklace of Beads Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7874   Accepted: 3290 ...

  9. CODEVS 3137 栈练习1

    3137 栈练习1 时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题目描述 Description 给定一个栈(初始为空,元素类型为整数,且小于等于100),只 ...

  10. (原+转)ubuntu终端输出彩色文字

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/6066697.html 参考网址: http://www.tuicool.com/articles/jI ...