UVA 156 Ananagrams ---map
题意:输入一些单词,找出所有满足如下条件的单词:该单词不能通过字母重排,得到输入文本中的另外一个单词。在判断是否满足条件时,字母不分大小写,但在输出时应保留输入中的大小写,按字典序进行排列(所有大写字母在所有小写字母的前面)。
刘汝佳算法竞赛入门经典(第二版)P113
#include <cstdio>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <algorithm>
#include <cctype>
#include <iostream>
using namespace std;
string repr(const string& s)
{
string ans=s;
for(int i=;i<ans.length();i++)
ans[i]=tolower(ans[i]);
sort(ans.begin(),ans.end());
return ans;
}
map<string,int> cnt;
vector<string> words;
int main()
{
int n=;
string s;
while(cin>>s)
{
if(s[]=='#') break;
words.push_back(s);
string r=repr(s);
if(!cnt.count(r)) cnt[r]=;
cnt[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;
return ;
}
/*
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
# */
UVA 156 Ananagrams ---map的更多相关文章
- uva 156 - Ananagrams (反片语)
csdn:https://blog.csdn.net/su_cicada/article/details/86710107 例题5-4 反片语(Ananagrams,Uva 156) 输入一些单词,找 ...
- UVa 156 Ananagrams(STL,map)
Ananagrams Most crossword puzzle fans are used to anagrams--groups of words with the same letters ...
- UVA 156 Ananagrams (STL multimap & set)
原题链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=98&p ...
- UVa 156 Ananagrams
题意:给出一些单词,在这些单词里面找出不能通过字母重排得到的单词(判断的时候不用管大小写),然后按照字典序输出. 学习的紫书的map= = 将每一个单词标准化 先都转化为小写,再排序(即满足了题目中说 ...
- uva 156 (map)
暑假培训习题 1.用vector<string>储存string类型的输入单词: 2.将vector中的元素逐一标准化后映射进map中,并给map值加一: 3.新建一个空的vector 4 ...
- STL语法——映射:map 反片语(Ananagrams,UVa 156)
Description Most crossword puzzle fans are used to anagrams--groups of words with the same letters i ...
- 【UVA - 156 】Ananagrams (set,map,vector)
Ananagrams Descriptions: Most crossword puzzle fans are used to anagrams--groups of words with the ...
- UVA 156:Ananagrams (vector+map+sort)
题意:一大堆单词中间有空格隔开,以'#'结束输出,问只出现一次的的单词有哪些(如果两个具有相同的长度,相同的字母也算是相同的,不区分大小写,如:noel和lone属于一个单词出现两次).最后按照字典序 ...
- UVa 156 (映射 map)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
随机推荐
- R-数据导入
目录 键盘输入 导入文本文件 导入Excel文件 访问数据库管理系统 键盘输入 > mydata <- data.frame(age=numeric(0), gender=characte ...
- AngularJS 国际化——Angular-translate
对于一个用户群面向全球的的应用来说,不得不考虑国际化的问题.当然,即便是刚刚起步的小应用,如果有心搞大,也应该提前设计国际化的方案. 本篇讲述使用AngularJS构建的应用的简单国际化方案,准确的说 ...
- pipe-filter 真难找啊
http://blog.csdn.net/absurd/article/details/4307903
- Longest Common Subsequence
Given two strings, find the longest common subsequence (LCS). Your code should return the length of ...
- 160809228_符瑞艺_C语言程序设计实验3 循环结构程序设计
#include <stdio.h> int main(){ //使用for循环完成1+2+......+100 ; ;i<=;i++) sum +=i; //sum = sum ...
- Ngrok搭建服务器
一.ngrok简介及作用 ngrok 是一款用go语言开发的开源软件,它是一个反向代理,通过在公共的端点和本地运行的 Web 服务器之间建立一个安全的通道.下图简述了ngrok的原理. ngrok 可 ...
- js之作用域和面向对象
作用域 JavaScript以函数为作用域 函数的作用域在函数未被调用之前,已经创建 函数的作用域存在作用域链,并且也是在被调用之前创建 示例一 xo = "alex"; func ...
- 1.7---将矩阵元素为0的行列清零0(CC150)
答案: import java.util.ArrayList; import java.util.List; public class Solution{ public static void mai ...
- CPU时间戳获取
inline long long timt(){ long long p; int&a=*(((int*)&p)+1); __asm__ __volatile__("rdts ...
- phpcms新闻详情页上一篇下一篇的实现
在新闻详情页(show.html或show_*.html) 只需要添加类似如下代码即可: <div>上一篇:<a href="{$previous_page[url]}&q ...