UVa156.Ananagrams
题目连接: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的更多相关文章
- UVa156 Ananagrams(映射map)
Ananagrams 题目 Most crossword puzzle fans are used to anagrams--groups of words with the same letters ...
- UVa-156 Ananagrams(map映射)
#include <iostream> #include <algorithm> #include <cmath> #include <cstdio> ...
- UVa-156 Ananagrams 反片语【map】【vector】
题目链接:https://vjudge.net/contest/211547#problem/D 题目大意: 输入一些单词,找出所有满足以下条件的单词:该单词不能通过字母重排,得到输入文本中的另外一些 ...
- uva-156(Ananagrams UVA - 156)
map容器的模板题,判断是否能交换字母顺序变成另外一个单词,只需要先把单词都变成小写字母.然后再按字母字典序排序,放入map中进行计数,然后把计数为一的再放入另一个容器,再排序输出即可 我的代码(刘汝 ...
- 【UVA - 156 】Ananagrams (set,map,vector)
Ananagrams Descriptions: Most crossword puzzle fans are used to anagrams--groups of words with the ...
- ACM题目————STL练习之Ananagrams
Description Most crossword puzzle fans are used to anagrams--groups of words with the same letters i ...
- STL语法——映射:map 反片语(Ananagrams,UVa 156)
Description Most crossword puzzle fans are used to anagrams--groups of words with the same letters i ...
- uva 156 - Ananagrams (反片语)
csdn:https://blog.csdn.net/su_cicada/article/details/86710107 例题5-4 反片语(Ananagrams,Uva 156) 输入一些单词,找 ...
- Winter-2-STL-F Ananagrams 解题报告及测试数据
Time Limit:3000MS Memory Limit:0KB Description Most crossword puzzle fans are used to anagrams- ...
随机推荐
- poj1011 Sticks(dfs+剪枝)
Sticks Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 110416 Accepted: 25331 Descrip ...
- thinkphp分页时修改last显示标题
需要修改Page.class.php里lastSuffix为false,这样才能修改last显示标题. 然后就可以设置了 或者直接在方法中声明: $p->lastSuffix = false; ...
- c指针点滴1
#include <stdio.h> #include <stdlib.h> void main() { ; int *p = #//&num是一个地址 ...
- WPF - 为什么不能往Library的工程中添加WPF window
项目中添加一个Library 工程,但是却无法加入WPF window, WPF customize control. 调查了一下,发现这一切都由于Library工程中没有:ProjectTypeGu ...
- java bootstrap分页
样式如下 datumMap.total总共多少页 datumMap.page第几页 <nav class="pull-right"> <ul class=&quo ...
- DB2查询当前时间与指定时间的时间差(相隔的秒数)
DB2查询当前时间与指定时间的时间差(相隔的秒数). 例子:“拍品表 auct_item”中有个“结束时间 end_date”的字段,求结束时间与当前时间的间隔秒数. select (DAYS(a. ...
- 使用VTemplate模板引擎动态生成订单流程图
1.VTemplate模板引擎的简介 VTemplate模板引擎也简称为VT,是基于.NET的模板引擎,它允许任何人使用简单的类似HTML语法的模板语言来引用.NET里定义的对象.当VTemplate ...
- 关于IE11
最近,一个开发代号为Windows Blue的Windows操作系统泄漏到了互联网上,该操作系统的内置浏览器为IE11,本文将介绍一下这个泄漏版的IE11中有哪些关键的新变化和新特性. 预先声明: 本 ...
- myeclipse修改内存
安装完成后,在安装目录有个config.ini文件,内容如下:-vmargs-Xms40m-Xmx256m Xms:初始化内存大小xmx:最大内存大小用编辑工具打开他,把Xms 和Xmx更改成自己需要 ...
- iOS RGB颜色封装
使用类别创建 .h文件 #import <UIKit/UIKit.h> @interface UIColor (HexColor) + (UIColor *)colorWithHex:(N ...