题目链接: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的使用)的更多相关文章

  1. POJ3320 Jessica's Reading Problem(尺取+map+set)

    POJ3320 Jessica's Reading Problem set用来统计所有不重复的知识点的数,map用来维护区间[s,t]上每个知识点出现的次数,此题很好的体现了map的灵活应用 #inc ...

  2. POJ 3320 Jessica's Reading Problem 尺取法/map

    Jessica's Reading Problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7467   Accept ...

  3. UVA Ananagrams /// map set

    https://vjudge.net/problem/UVA-156 题目大意: 输入文本,找出所有满足条件的单词——该单词不能通过字母重排而得到输入的文本中的另外一个单词. 在判断是否满足条件时,字 ...

  4. UVA 156 Ananagrams ---map

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

  5. UVa-156 Ananagrams(map映射)

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

  6. 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 ...

  7. ZOJ3209 Treasure Map —— Danc Links 精确覆盖

    题目链接:https://vjudge.net/problem/ZOJ-3209 Treasure Map Time Limit: 2 Seconds      Memory Limit: 32768 ...

  8. PAT_A1111#Online Map

    Source: PAT A1111 Online Map (30 分) Description: Input our current position and a destination, an on ...

  9. python:map 函数

    map(func, *iterables) --> map object map()是 Python 内置的高阶函数,它接收一个函数 func 和一个 list(*iterables),并通过把 ...

随机推荐

  1. java 一致性哈希类实例 算法

    package com.hash; import java.util.Collection; import java.util.SortedMap; import java.util.TreeMap; ...

  2. linux中读写锁的rwlock介绍-nk_ysg-ChinaUnix博客

    linux中读写锁的rwlock介绍-nk_ysg-ChinaUnix博客 linux中读写锁的rwlock介绍 2013-02-26 13:59:35 分类: C/C++   http://yaro ...

  3. mongoose 查询子文档的方法

    { "__v": 1, "_id": "538f5f0f6195a184108c8bd8", "title": &quo ...

  4. 走进小作坊(十一)----移动web实现指南

    四.五年前智能手机行业刚刚兴起,差别于之前功能机阉割版的web开发方式,一些学者就開始探索移动web的UI方向了.从PC迁移到移动端的web设计现成可用的原则有,很多其它的则是依据移动端独有特点进行探 ...

  5. api文档生成工具 C#

    要为编写的程序编写文档,这是件费力气的事,如果能自动生成就好了. 不怕做不到,就怕想不到.这不,搜索到了Sandcastle 比较好的参考文章: 1.Sandcastle官方网址: http://sh ...

  6. jquery新增,删除 ,修改,清空select中的option

    jQuery获取Select选择的Text和Value: 1. var checkText=jQuery("#select_id").find("option:selec ...

  7. C# 创建文件时,文件夹不存在,如何自动创建文件夹

    c# 创建文件时怎么创建文件夹?strhtml=......StreamWriter sw=new StreamWriter("D:/test/1.aspx",false);sw. ...

  8. [C++]Standing Ovation——Google Code Jam 2015 Qualification Round

    Problem It’s opening night at the opera, and your friend is the prima donna (the lead female singer) ...

  9. [C++]Store Credit——Google Code Jam Qualification Round Africa 2010

    Google Code Jam Qualification Round Africa 2010 的第一题,很简单. Problem You receive a credit C at a local ...

  10. valgrind用于检测内存泄露

    http://www.thegeekstuff.com/2011/11/valgrind-memcheck/