ACM题目————STL练习之Ananagrams
Description

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 题目很简单,就是说给定一些字符串(以#结束),把这些字符串排序(不区分大小写),然后输出出现过两次以上的字符串(按字典顺序,也就是按ASII码表)。
//Asimple
#include <iostream>
#include <vector>
#include <string>
#include <map> using namespace std; typedef multimap<string,string>::iterator mss_iter;
multimap<string,string> m;
string str; int main()
{
while ( cin >> str )
{
if( str == "#" ) break ;
string str_copy(str);
for(int i=0; i<str_copy.size(); i++)
str_copy[i] = tolower(str_copy[i]);
sort(str_copy.begin(),str_copy.end());//排序
m.insert(make_pair(str_copy,str));//将排序后的字符串和原字符串放进一个容器
}
vector<string> S;
for( mss_iter it=m.begin(); it!=m.end(); it++)
if( m.count( it->first) == 1 )
S.push_back( it->second) ;
sort(S.begin(),S.end());
for( int i=0; i<S.size(); i++)
cout << S[i] << endl ; return 0;
}
ACM题目————STL练习之Ananagrams的更多相关文章
- ACM题目————STL练习之求次数
题目地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=1112 描述 题意很简单,给一个数n 以及一个字符串str,区间[i,i+n-1] 为一个 ...
- ACM题目————STL练习之字符串替换
描述 编写一个程序实现将字符串中的所有"you"替换成"we" 输入 输入包含多行数据 每行数据是一个字符串,长度不超过1000 数据以EOF结束 输出 对于输 ...
- ACM题目————STL练习之众数问题
描述 所谓众数,就是对于给定的含有N个元素的多重集合,每个元素在S中出现次数最多的成为该元素的重数, 多重集合S重的重数最大的元素成为众数.例如:S={1,2,2,2,3,5},则多重集S的众数是2, ...
- ACM题目————STL练习之 懒省事的小明(优先队列)
描述 小明很想吃果子,正好果园果子熟了.在果园里,小明已经将所有的果子打了下来,而且按果子的不同种类分成了不同的堆.小明决定把所有的果子合成一堆. 因为小明比较懒,为了省力气,小明开始想点子了: 每一 ...
- ACM题目————STL + 全排列
今天碰到一个函数,感觉挺好用的,全排列函数 next_permutation! 求全排列的函数,基本上与自己写的DFS时间复杂度差不多,毕竟是标准库.(2018-1-4 添加) 话不多说,直接上题. ...
- ACM题目———— 一种排序(STL之set)
描述 输入 第一行有一个整数 0<n<10000,表示接下来有n组测试数据:每一组第一行有一个整数 0<m<1000,表示有m个长方形:接下来的m行,每一行有三个数 ,第一个数 ...
- ACM题目————中缀表达式转后缀
题目描述 我们熟悉的表达式如a+b.a+b*(c+d)等都属于中缀表达式.中缀表达式就是(对于双目运算符来说)操作符在两个操作数中间:num1 operand num2.同理,后缀表达式就是操作符在两 ...
- HDU ACM 题目分类
模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 104 ...
- ACM题目推荐(刘汝佳书上出现的一些题目)[非原创]
原地址:http://blog.csdn.net/hncqp/article/details/1758337 推荐一些题目,希望对参与ICPC竞赛的同学有所帮助. POJ上一些题目在http://16 ...
随机推荐
- iOS - (几个 button 按钮之间的单选与多选)
先来看看效果图: 下面是实现的代码: 首先创建10个button(一个一个写太麻烦了,个人认为还是用一个 for 循环来创建比较好) 下面就是 button 的点击方法实现单选 多选的比较好做,写法也 ...
- XMPP协议介绍
一.xmpp协议工作原理 二.XMPP地址模式 三.xmpp消息格式 xmpp xml包括三个元素,message,presence,iq,也翻译做三种节. 在'jabber:client'和'jab ...
- ssh tunnel通道
Secure SHell (SSH) 是一个通过网络登录其他计算机的程序,在远程服务器运行命令,和从一台机器移动文件到另一台.在不安全的网络中,它提供两台主机之间强大认证和安全加密的的通讯,被称为 S ...
- PostgreSQL Replication之第十二章 与Postgres-XC一起工作(7)
12.7 处理故障转移和删除节点 在本节中,我们将看看故障切换如何处理.我们还将看看如何使用安全可靠的方法添加节点到Postgres-XC设置以及如何从Postgres-XC设置删除节点. 12.7. ...
- Leetcode: Convert a Number to Hexadecimal
Given an integer, write an algorithm to convert it to hexadecimal. For negative integer, two's compl ...
- Winform 基本属性
WinForm--- 客户端应用程序 - 是需要安装在用户电脑上才可以使用的程序特点:不需要联网也可以打开使用部分功能但是现在的情况是许多功能依然需要互联网的支持 代码部分在用户电脑上执行 WinFo ...
- 【Origin】jquery.barddialog.js
/// <reference path="jquery-2.1.1.min.js" /> /** * @license jquery.bardDialog 1.0.0 ...
- codevs 1203 判断浮点数是否相等
http://codevs.cn/problem/1203/ 1203 判断浮点数是否相等 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 青铜 Bronze 题解 查看运行 ...
- C++之路起航——标准模板库(set)
set(集合):http://baike.baidu.com/link?url=cb68AB-3qfEK8RoaGHJFClb4ZiWpJfc32lPOLtaNUrdxntFC738zCZsCiUlf ...
- paper 28 :一些常见常用数据库的下载网站集锦
做图像处理+模式识别的童鞋怎么可以没有数据库呢? 但是,如果自己做一个数据库,费时费力费钱先不说,关键是建立的数据库的公信力一般不会高,做出的算法也别人也不好比较,所以呢,下载比较权威的公共数据库还是 ...