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),并通过把 ...
随机推荐
- Android NDK 编译FFmpeg(不需要复杂的环境变量设置)
环境: CentOS6.2——64位 借鉴:https://vec.io/posts/how-to-build-ffmpeg-with-android-ndk 在根目录下创建work文件夹:cd / ...
- netbeans字体与颜色配置模板相关网站
NetBeans Themes -Color Schemes of the NetBeans IDE NetBeans ThemeBuilder
- iOS深入学习 (Block全面分析)
本文翻译自苹果的文档,有删减,也有添加自己的理解部分. 如果有Block语法不懂的,可以参考fuckingblocksyntax,里面对于Block 为了方便对比,下面的代码我假设是写在ViewCon ...
- JavaScript引用类型之Array数组之强大的splice()方法
splice()方法可以说是Array数组最强大的方法,他的用法很多,主要用法是向数组的中部插入项! 下面是它的用法: arrayObject.splice(index,howmany,element ...
- nodejs教程:安装express及配置app.js文件
express.js是nodejs的一个MVC开发框架,并且支持jade等多种模板.下面简单来说说express的安装和app.js文件的配置,然后在今后的教程中一步一步使用express.js搭建个 ...
- Nio Client
public class NIOClient { static int SIZE = 2; final static int bufferSize = 500 * 1024; static InetS ...
- 获取extjs text列修改过 数据
ExtJS中表格的特性简介 表格由类Ext.grid.GridPanel定义,继承自Ext.Panel,xtype为grid 表格的列信息由Ext.grid.ColumnModel定义 表格的数据存储 ...
- Hadoop学习之HBase和Hive的区别
Hive是为简化编写MapReduce程序而生的,使用MapReduce做过数据分析的人都知道,很多分析程序除业务逻辑不同外,程序流程基本一样.在这种情况下,就需要Hive这样的用户编程接口.Hive ...
- 整理部分JS 控件 WEB前端常用的做成Jsp项目,方便今后直接用
整理部分JS 控件 WEB前端常用的做成Jsp项目,方便今后直接用 最近又没时间了,等用时间了,再加入更多的, 源码下载: http://download.csdn.net/detail/liang ...
- Use API to retrieve data from internet
Reference: Working with APIs Many big companies and organizations provide API for us to retrieve dat ...