输入一些单词,找出所有满足如下条件的单词:

该单词不能通过字母重排,得到输入文本中的另外一个单词。

在判断是否满足条件时,不区分大小写,但输出保留输入中的大小写,按字典序进行排列(所有大写字母在小写字母的前面)

样例输入:

ladder came tape soon leader acme RIDE lone Dreis peat

ScALE orb eye Rides dealer NotE derail LaCeS drIed

noel dire Disk mace Rob dires

#

样例输出:

Disk
NotE
derail
drIed
eye
ladder
soon

分析:把每个单词“标准化”,即全部转化为小写字母后再进行排序,然后再放到map中进行统计

#include<iostream>
#include<string>
#include<cctype>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
map<string,int>cnt;
vector<string>words; string repr(const string & s) //将单词s进行标准化
{
string ans=s;
for(int i=;i<ans.length();i++)
ans[i]=tolower(ans[i]);
sort(ans.begin(),ans.end()); //sort可以对任意对象进行排序
return ans;
}
int main()
{
int n=;
string s;
while(cin>>s){
if(s[]=='#')break;
words.push_back(s); //在vector words尾部加入一个数据s
string r=repr(s); //r为标准化后的字符串
if(!cnt.count(r))cnt[r]=; //count(n) 返回容器中n出现的次数 若为0,则将r存入容器中,并初始个数为0
cnt[r]++; //r对应的int个数 加一 ,该值即为r出现的次数
}
vector<string>ans;
for(int i=;i<words.size();i++)
if(cnt[repr(words[i])]==)ans.push_back(words[i]);
sort(ans.begin(),ans.end());
for(int i=;i<ans.size();i++)cout<<ans[i]<<endl;
//system("pause");
return ;
}

反片语(map)的更多相关文章

  1. uva 156 - Ananagrams (反片语)

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

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

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

  3. UVa-156 Ananagrams 反片语【map】【vector】

    题目链接:https://vjudge.net/contest/211547#problem/D 题目大意: 输入一些单词,找出所有满足以下条件的单词:该单词不能通过字母重排,得到输入文本中的另外一些 ...

  4. 【C/C++】例题5-4 反片语/算法竞赛入门经典/C++与STL入门/映射:map

    本题是映射:map的例题. map:键值对. [题目] 输入一些单词,找出所有满足如下条件的单词:该单词不能通过字母重排,得到输入文本中的另外一个单词. 在判断是否满足条件时,字母不分大小写,但在输出 ...

  5. 5_4 反片语(UVa156)<map的使用>

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

  6. 反片语 UVA 156

    //该单词不能通过字母重排,得到输入文本中的另外一个单词.在判断是否满足条件时,字母部分大小写 #include<iostream> #include<vector> #inc ...

  7. 反片语(UVa156)

    题目具体描述见:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=835&a ...

  8. 反片语 (Ananagrams,UVa 156)

    题目描述: #include <iostream> #include <string> #include <cctype> #include <vector& ...

  9. 反片语(Ananagrams,Uva 156)

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

随机推荐

  1. css盒子模型,定位,浮动

    1.盒子模型 Margin(外边距) - 清除边框外的区域,外边距是透明的. Border(边框) - 围绕在内边距和内容外的边框. Padding(内边距) - 清除内容周围的区域,内边距是透明的. ...

  2. (原)error LNK2038: 检测到“_ITERATOR_DEBUG_LEVEL”的不匹配项: 值“0”不匹配值“2”

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5577534.html 在debug下使用intel的mkl库时(release下无此问题),莫名的出现 ...

  3. 【solr专题之二】配置文件:solr.xml solrConfig.xml schema.xml

    1.关于默认搜索域 If you are using the Lucene query parser, queries that don't specify a field name will use ...

  4. URL锚点定位

    我们都知道<a>标签中的url属性有三种值: 绝对 URL - 指向另一个站点(比如 href="http://www.example.com/index.htm") ...

  5. typecho博客出404页面修改方法

    适用于typecho博客版本为:0.9 (13.12.12) typecho博客,很多时候可能安装完毕,除了首页,其他页面都是404=.= 在匹配*.php的location区域修改为以下格式: lo ...

  6. Linux上使用Azure CLI来管理Azure

    在Windows上我们有强大的Powershell提供各种命令来管理Azure的服务,在Linux上微软提供了基于Node.JS的跨平台的Azure Command Line来帮助Linux用户来管理 ...

  7. jQuery中$.proxy()的原理和使用

    jQuery.proxy(),接受一个函数,然后返回一个新函数,并且这个新函数始终保持了特定的上下文(context )语境. jQuery.proxy( function, context ) fu ...

  8. SQL排除重复结果只取字段最大值

    如何用SQL排除重复结果只取字段最大值的记录?要求得到的结果(即是PID相同的记录只取ID值最大的那一条). select * from [Sheet1$] a from [Sheet1$] wher ...

  9. LeetCode_Letter Combinations of a Phone Number

    Given a digit string, return all possible letter combinations that the number could represent. A map ...

  10. web service c# 互调 java (转)

    一:简介 本文介绍了Java与.NET开发的Web Services相互调用的技术.本文包括两个部分,第一部分介绍了如何用.NET做客户端调用Java写的Web Services,第二部分介绍了如何用 ...