原题链接:

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=98&page=show_problem&problem=92

整体思路如下:先建立一个 multimap<排序的词,未排序的词> 来处理输入,完毕后将只有一个值的键放入一个set中,最后遍历set输出即可。切忌不要误用成 map, 因为 multimap 允许重复元素,map 不允许有重复

更多有关 map 与 multimap 的区别可以查看这篇博客:https://blog.csdn.net/c_base_jin/article/details/51501214

下面就奉上 AC 代码:

#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <map> using namespace std; char ch[25], origin[25]; multimap <string, string> mmp;
set <string> con; int main(void)
{
int len, i;
while (scanf("%s", ch), ch[0] != '#') {
strcpy(origin, ch);
len = strlen(ch); for (int i = 0; i < len; i++)
if (isupper(ch[i]))
ch[i] = tolower(ch[i]); sort(ch, ch + len);
mmp.insert(make_pair(ch, origin));
} multimap <string, string>::iterator xp;
set <string>::iterator it;
for (xp = mmp.begin(); xp != mmp.end(); xp++)
if (mmp.count(xp -> first) == 1)
con.insert(xp -> second);
for (it = con.begin(); it != con.end(); it++)
puts((*it).c_str()); return 0;
}

UVA 156 Ananagrams (STL multimap & set)的更多相关文章

  1. UVa 156 Ananagrams(STL,map)

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

  2. uva 156 - Ananagrams (反片语)

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

  3. UVA 156 Ananagrams ---map

    题目链接 题意:输入一些单词,找出所有满足如下条件的单词:该单词不能通过字母重排,得到输入文本中的另外一个单词.在判断是否满足条件时,字母不分大小写,但在输出时应保留输入中的大小写,按字典序进行排列( ...

  4. UVa 156 Ananagrams

    题意:给出一些单词,在这些单词里面找出不能通过字母重排得到的单词(判断的时候不用管大小写),然后按照字典序输出. 学习的紫书的map= = 将每一个单词标准化 先都转化为小写,再排序(即满足了题目中说 ...

  5. STL语法——映射:map 反片语(Ananagrams,UVa 156)

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

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

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

  7. 反片语(Ananagrams,Uva 156)

    输入一些单词,找出所有满足如下条件的单词:该单词不能通过字母重排,得到输入文 本中的另外一个单词.在判断是否满足条件时,字母不分大小写,但在输出时应保留输入中 的大小写,按字典序进行排列(所有大写字母 ...

  8. Ananagrams UVA - 156

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

  9. UVA 156:Ananagrams (vector+map+sort)

    题意:一大堆单词中间有空格隔开,以'#'结束输出,问只出现一次的的单词有哪些(如果两个具有相同的长度,相同的字母也算是相同的,不区分大小写,如:noel和lone属于一个单词出现两次).最后按照字典序 ...

随机推荐

  1. Windows 10 彻底关闭 Antimalware Service Executable 降低内存占用

    概述 最近给内网的一台电脑安装 Windows 10 专业版系统,由于此电脑不会涉及到不安全因素,所以杀毒软件非必须. 以最大限度节省系统资源考虑,默认安装的 Micoroft Defender 占用 ...

  2. 删除其他列Table.SelectColumns(Power Query 之 M 语言)

    数据源: "姓名""基数""个人比例""个人缴纳""公司比例""公司缴纳"&qu ...

  3. 嵌入式实验一:LED灯点亮

    实验一:LED灯程序 一. 实验环境 开发机环境 ​ 操作系统:ubuntu 12.04 ​ 交叉编译环境:arm-linux-gcc 4.3.2 ​ 6410板子内核源码:linux-3.0.1 目 ...

  4. VC Mirror Driver显示虚拟驱动经典开发

    一个简单的显示驱动实例windows wdk 7600的 mirror(镜像) 显示驱动部分基本流程:Windows 2000 DDK包含了一个例子镜像驱动程序,在 上面3个目录中包括了组件源文件.目 ...

  5. 总结Vue 第四天:vue-cli(Vue2.0 新手入门 — 从环境搭建到发布)

    总结Vue 第四天:vue-cli(Vue2.0 新手入门 - 从环境搭建到发布) 一.Vue CLI----(Vue2.0 新手入门 - 从环境搭建到发布): ■   CLI是Command-Lin ...

  6. 【LeetCode】1461. 检查一个字符串是否包含所有长度为 K 的二进制子串 Check If a String Contains All Binary Codes of Size K

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 统计长度为 K 的子串个数 日期 题目地址:https ...

  7. 【LeetCode】230. 二叉搜索树中第K小的元素 Kth Smallest Element in a BST

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 公众号:负雪明烛 本文关键词:算法题,刷题,Leetcode, 力扣,二叉搜索树,BST ...

  8. 【LeetCode】393. UTF-8 Validation 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/utf-8-va ...

  9. 【LeetCode】645. Set Mismatch 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 Hash方法 直接计算 日期 题目地址: https ...

  10. 【LeetCode】729. My Calendar I 解题报告

    [LeetCode]729. My Calendar I 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/my-calendar- ...