UVa 156 Ananagrams
题意:给出一些单词,在这些单词里面找出不能通过字母重排得到的单词(判断的时候不用管大小写),然后按照字典序输出。
学习的紫书的map= =
将每一个单词标准化 先都转化为小写,再排序(即满足了题目中说的不能通过字母重排这个条件) 然后记录出现次数,将出现次数为1的储存再输出
话说这一题的标准化要好好学学= =(字母重排用排序来做= =)
- #include<iostream>
- #include<cstdio>
- #include<cstring>
- #include<vector>
- #include<algorithm>
- #include<cctype>
- #include<set>
- #include<map>
- using namespace std;
- map<string,int> cnt;
- vector<string> words;
- vector<string> ans;
- 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;
- }
- int main()
- {
- string s;
- while(cin>>s)
- {
- if(s[]=='#') break;
- words.push_back(s);
- string r=repr(s);
- if(!cnt.count(r)) cnt[r]=;
- cnt[r]++;
- }
- 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]<<"\n";
- return ;
- }
UVa 156 Ananagrams的更多相关文章
- 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
题目链接 题意:输入一些单词,找出所有满足如下条件的单词:该单词不能通过字母重排,得到输入文本中的另外一个单词.在判断是否满足条件时,字母不分大小写,但在输出时应保留输入中的大小写,按字典序进行排列( ...
- 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 ...
- Ananagrams UVA - 156
Most crossword puzzle fans are used to anagrams - groups of words with the same letters in differe ...
- UVA 156:Ananagrams (vector+map+sort)
题意:一大堆单词中间有空格隔开,以'#'结束输出,问只出现一次的的单词有哪些(如果两个具有相同的长度,相同的字母也算是相同的,不区分大小写,如:noel和lone属于一个单词出现两次).最后按照字典序 ...
- 反片语 (Ananagrams,UVa 156)
题目描述: #include <iostream> #include <string> #include <cctype> #include <vector& ...
随机推荐
- 哪些问题困扰着我们?DevOps 使用建议
[编者按]随着 DevOps 被欲来越多机构采用,一些共性的问题也暴露出来.近日,Joe Yankel在「Devops Q&A: Frequently Asked Questions」一文中总 ...
- NodeJS模块、包、NPM
1.NodeJS模块 每一个Nodejs都是一个NodeJS模块,包括JS文件,JSON文本文件,二进制模块文件. a.模块的应用 新建一个文件mytest. ...
- uva 11294
Problem E: Wedding Up to thirty couples will attend a wedding feast, at which they will be seated on ...
- POJ 3484
Showstopper Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1060 Accepted: 303 Descri ...
- iOS 隐藏顶部状态栏方式和更改颜色
plist文件里面添加 AppDelegate: //显示状态栏 [[UIApplication sharedApplication]setStatusBarHidden:NO]; //将状态栏颜色设 ...
- POJ 2075
#include<iostream> #include<stdio.h> #include<string> #include<map> #include ...
- java 如何从配置文件(.properties)中读取内容
1.如何创建.properties文件 很简单,建立一个txt文件,并把后缀改成.properties即可 2.将.properties文件拷入src的根目录下 3..properties文件内容格式 ...
- regexp_substr在oracle9i的替换方案
regexp_substr()方法在oracle9i尚不存在,是从oracle10g开始新增,如下为替换解决方法. SELECT regexp_substr('|83~GT67XVFU0RCVIV|6 ...
- linux下如何查看主机的外网ip地址
在linux下如果我们使用的是nat方式上网.通过ifconfig命令查看到的ip地址往往是内网地址 那么如何查看主机在互联网上使用的公网IP呢?我们可以在命令行下使用curl命令实现这个功能. [r ...
- lintcode:将二叉查找树转换成双链表
题目 将一个二叉查找树按照中序遍历转换成双向链表 给定一个二叉查找树: 4 / \ 2 5 / \ 1 3 返回 1<->2<->3<->4<->5. ...