Problem D Ananagrams(map的使用)
题目链接:Problem D
题意:输入一些单词,找出所有满足如下条件的单词:该单词不能通过字母重排,得到输入文本中的另一个单词。在判断是否满足条件时,字母不区分大小写。
但是输出时应保留原始大小写,按字典序进行排列。
思路:把单词统一处理一下,然后放入map中,用vector记录下满足要求的单词,最后排序一下即可。
code:
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cctype>
using namespace std; vector<string> words;
map<string, int> cnt; string repr(string str)
{
string ret = str;
int len = ret.size();
for (int i = ; i < len; ++i)
ret[i] = tolower(ret[i]);
sort(ret.begin(), ret.end());
return ret;
} int main()
{
string str;
while (cin >> str)
{
if ('#' == str[]) break;
words.push_back(str);
string t = repr(str);
if (cnt.count(t) == ) cnt[t] = ;
++cnt[t];
}
int len = words.size();
vector<string> ans;
for (int i = ; i < len; ++i)
{
if ( == cnt[repr(words[i])])
ans.push_back(words[i]);
}
len = ans.size();
sort(ans.begin(), ans.end());
for (int i = ; i < len; ++i)
cout << ans[i] << endl;
return ;
}
Problem D Ananagrams(map的使用)的更多相关文章
- POJ3320 Jessica's Reading Problem(尺取+map+set)
POJ3320 Jessica's Reading Problem set用来统计所有不重复的知识点的数,map用来维护区间[s,t]上每个知识点出现的次数,此题很好的体现了map的灵活应用 #inc ...
- POJ 3320 Jessica's Reading Problem 尺取法/map
Jessica's Reading Problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7467 Accept ...
- UVA Ananagrams /// map set
https://vjudge.net/problem/UVA-156 题目大意: 输入文本,找出所有满足条件的单词——该单词不能通过字母重排而得到输入的文本中的另外一个单词. 在判断是否满足条件时,字 ...
- UVA 156 Ananagrams ---map
题目链接 题意:输入一些单词,找出所有满足如下条件的单词:该单词不能通过字母重排,得到输入文本中的另外一个单词.在判断是否满足条件时,字母不分大小写,但在输出时应保留输入中的大小写,按字典序进行排列( ...
- UVa-156 Ananagrams(map映射)
#include <iostream> #include <algorithm> #include <cmath> #include <cstdio> ...
- 2017年上海金马五校程序设计竞赛:Problem K : Treasure Map (蛇形填数)
Description There is a robot, its task is to bury treasures in order on a N × M grids map, and each ...
- ZOJ3209 Treasure Map —— Danc Links 精确覆盖
题目链接:https://vjudge.net/problem/ZOJ-3209 Treasure Map Time Limit: 2 Seconds Memory Limit: 32768 ...
- PAT_A1111#Online Map
Source: PAT A1111 Online Map (30 分) Description: Input our current position and a destination, an on ...
- python:map 函数
map(func, *iterables) --> map object map()是 Python 内置的高阶函数,它接收一个函数 func 和一个 list(*iterables),并通过把 ...
随机推荐
- CentOS7 vs centos6
The CentOS Project has announced general availability of CentOS-7, the first release of the free Lin ...
- iOS 退出应用程序
退出应用程序,方法很简单,只是动画效果没有那么好. - (void)exitApplication { AppDelegate *app = [UIApplication sharedApplicat ...
- Sequence operation(线段树区间多种操作)
Sequence operation Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- C++中的随机数函数(
标签:ul 随机数 c 整数 max 教育 C++中产生随机数种子对于刚開始学习的人一直都非常困惑.大家知道,在C中有专门的srand(N)函数能够轻松实现这一功能,然而在C++中则要复杂一些.以下 ...
- iOS 使用UILocalizedIndexedCollation实现区域索引标题(Section Indexed Title)即拼音排序
UITableView在行数相当多的时候,给人的感觉是非常笨重的.通常为了方便用户使用,采用的方法有:搜索框.按层级展示.区域索引标题. 前两种就不用介绍了,此文就介绍区域索引标题的实现. 区域索引标 ...
- wcf客户端 cookie
public class CookieBehavior:IEndpointBehavior { private string _cookie; #region 构造函数 重载+2 public Coo ...
- 关于win7系统的Oracle安装时的[INS-30131]问题的解决方案
我是今天晚上安装的Oracle,结果在第二步遇到了这个问题,前后折腾了两个小时,百度了很多解决方案,终于解决了这个问题; 由于我的电脑系统还是win7的系统,其他的我没试过,不过也差不多都这么解决; ...
- mongodb数据库调试问题:‘db object already connecting, open cannot be called multiple times’
在微博小系统的调试过程中: (1)登入登出可以正常显示,就是在注册的时候网络连接突然停止,但是用户名和密码已经存入数据库中,报错为:undefined is not a function 错误主要指向 ...
- MD5 加密 以及 加盐加密
这是MD5加密 - (NSString *)MD5Hash { const char *cStr = [self UTF8String]; unsigned char result[16]; CC_M ...
- NET Core开发-使用Nancy框架
NET Core开发-使用Nancy框架 Nancy简介 Nancy是一个轻量级的独立的框架,下面是官网的一些介绍: Nancy 是一个轻量级用于构建基于 HTTP 的 Web 服务,基于 .NET ...