https://vjudge.net/problem/UVA-156

题目大意:

输入文本,找出所有满足条件的单词——该单词不能通过字母重排而得到输入的文本中的另外一个单词。

在判断是否满足条件时,字母不分大小写,但在输出时应保留输入中的大小写,按字典序进行排序。

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

将所有单词转为小写再sort后存入map中,若已出现过则继续加1,若未出现过则先赋零再加1

将所有单词原文本存入set中,会直接按字典序排序,最后遍历set 判断 输出

#include <bits/stdc++.h>
using namespace std;
map <string,int> mp;
set <string> had;
string judge(string str)
{
string s=str;
for(int i=;i<s.length();i++)
s[i]=tolower(s[i]); ///将单词转为小写再排序
sort(s.begin(),s.end());
return s;
}
int main()
{
string str;
while(cin>>str)
{
had.insert(str); ///将原文本单词存入set
if(str[]=='#') break;
string temp=judge(str);
if(mp.count(temp)==) mp[temp]=;
mp[temp]++; ///转换后的单词是否出现过 无则赋零+1有则+1
}
set <string>::iterator iter;
for(iter=had.begin();iter!=had.end();iter++)
if(mp[judge(*iter)]==) cout<<*iter<<endl;
///为1表示没有重复只出现过一次
return ;
}

UVA Ananagrams /// map set的更多相关文章

  1. UVA 156 Ananagrams ---map

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

  2. UVa-156 Ananagrams(map映射)

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

  3. The Summer Training Summary-- the first

    The Summer Training Summary-- the first A - vector的使用 UVa 101 关于vector 的几个注意点 vector p p.push_back() ...

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

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

  5. UVa 156 Ananagrams(STL,map)

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

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

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

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

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

  8. uva 156 - Ananagrams (反片语)

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

  9. UVa 156 (映射 map)

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

随机推荐

  1. A. Srdce and Triangle--“今日头条杯”首届湖北省大学程序设计竞赛(网络同步赛)

    如下图这是“今日头条杯”首届湖北省大学程序设计竞赛的第一题,作为赛后补题 题目描述:链接点此 这套题的github地址(里面包含了数据,题解,现场排名):点此 Let  be a regualr tr ...

  2. postgresql数字类型

    postgresql的数据类型很多,也可以使用create type命令创建自定义数据类型,但常用的数据类型是以下三种: l  数字数据类型 l  字符串数据类型 l  日期/时间数据类型 数字数据类 ...

  3. Openstack组件部署 — Netwotking service组件介绍与网络基本概念

    目录 目录 前文列表 Openstack Networking serivce 基本的Neutron概念 Neutron的抽象对象 网络networks 子网subnets 路由器routers 端口 ...

  4. python中面向对象之装饰器

    python面向对象内置装饰器property,staticmethod,classmethod的使用 @property 装饰器作用及使用 作用:面向对象中的方法伪装成属性 使用如下: class ...

  5. zabbix4.0自动注册实践

    共分为两个步骤: 1.主机zabbix_agent客户端的配置文件 2.主机zabbix_server网页端的自动注册配置 zabbix_agent配置文件 Server=192.168.100.15 ...

  6. springboot启动方式

    第一种(本地开发使用)在项目的根目录下有一个带有main函数的Application类,可以直接执行这个main函数.(使用的是SpringBoot内置的tomcat) 第二种(本地开发使用)在pom ...

  7. Google Fuchsia

    Fuchsia是Google开发的操作系统[1].和以前Google开发的操作系统,如基于Linux内核的Chrome OS和Android等不同,Fuchsia基于新的名为Zircon的微内核[2] ...

  8. boost asio tcp 多线程

    common/pools.h // common/pools.h #pragma once #include <string> #include <boost/pool/pool.h ...

  9. Sublime Text3中MarkDown的使用

    前言 当我们想要在Sublime文本编辑器中编辑markdown时,需要先安装markdown插件,因为Sublime里默认没有安装该插件,同时在编辑markdown文本时可以实时预览编辑效果. 具体 ...

  10. Tools: CGAL 安装指南

    环境:Microsoft Win7 SP1 Visual Studio 2015 SP3 参考: https://blog.csdn.net/milkpku/article/details/50241 ...