UVA 156:Ananagrams (vector+map+sort)
题意:一大堆单词中间有空格隔开,以‘#’结束输出,问只出现一次的的单词有哪些(如果两个具有相同的长度,相同的字母也算是相同的,不区分大小写,如:noel和lone属于一个单词出现两次)。最后按照字典序输出那些只出现一次的单词
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <limits.h>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <string>
#define ll long long
#define ms(a) memset(a,0,sizeof(a))
#define pi acos(-1.0)
#define INF 0x3f3f3f3f
const double E=exp(1);
const int maxn=1e6+10;
using namespace std;
vector<string> v;
map<string,int> mmp;
//将字符串转换成小写,并将该字符串中的字符按字典序排序
string change(string a)
{
for(int i=0;i<a.length();i++)
a[i]=tolower(a[i]);
sort(a.begin(),a.end());
return a;
}
int main(int argc, char const *argv[])
{
ios::sync_with_stdio(false);
string ch;
while(cin>>ch&&ch[0]!='#')
{
//单词存入v
v.push_back(ch);
//将单词转化一下,用map标记
string word=change(ch);
mmp[word]++;
}
vector<string>ans;
for(int i=0;i<v.size();i++)
{
//如果单词出现一次,将该单词加入ans中
if(mmp[change(v[i])]==1)
ans.push_back(v[i]);
}
//字典序排序
sort(ans.begin(),ans.end());
for(int i=0;i<ans.size();i++)
cout<<ans[i]<<endl;
return 0;
}
UVA 156:Ananagrams (vector+map+sort)的更多相关文章
- 【UVA - 156 】Ananagrams (set,map,vector)
Ananagrams Descriptions: Most crossword puzzle fans are used to anagrams--groups of words with the ...
- cocos2dx的模板容器简单使用(Vector,Map,Value)
在cocos2dxv3.0beta之前存在顺序性容器cocos2d::CCArray,和cocos2d::CCDictionary.可是在新版本号之后这两个容器都将被cocos2d::Vector&l ...
- (转载)项目实战工具类(一):PhoneUtil(手机信息相关)
项目实战工具类(一):PhoneUtil(手机信息相关) 可以使用的功能: 1.获取手机系统版本号 2.获取手机型号 3.获取手机宽度 4.获取手机高度 5.获取手机imei串号 ,GSM手机的 ...
- 一缕阳光:DDD(领域驱动设计)应对具体业务场景,如何聚焦 Domain Model(领域模型)?
写在前面 阅读目录: 问题根源是什么? <领域驱动设计-软件核心复杂性应对之道>分层概念 Repository(仓储)职责所在? Domain Model(领域模型)重新设计 Domain ...
- 排序之直接插入排序(Straight Insertion Sort)
一.直接插入排序(Straight Insertion Sort) 排序的过程如下:给定无需序列:(3,6,9,7,1,8,2,4) ① 3,6,9,7,1,8,2,4 (将6插入到有序序列3中) ② ...
- 简单选择排序(Simple Selection Sort)的C语言实现
简单选择排序(Simple Selection Sort)的核心思想是每次选择无序序列最小的数放在有序序列最后 演示实例: C语言实现(编译器Dev-c++5.4.0,源代码后缀.cpp) 原创文章, ...
- 希尔排序(Shell's Sort)的C语言实现
原创文章,转载请注明来自钢铁侠Mac博客http://www.cnblogs.com/gangtiexia 希尔排序(Shell's Sort)又称“缩小增量排序”(Diminishing Incre ...
- 2-路插入排序(2-way Insertion Sort)的C语言实现
原创文章,转载请注明来自钢铁侠Mac博客http://www.cnblogs.com/gangtiexia 2-路插入排序(2-way Insertion Sort)的基本思想: 比fis ...
- 折半插入排序(Binary Insertion Sort)的C语言实现
原创文章,转载请注明来自钢铁侠Mac博客http://www.cnblogs.com/gangtiexia 折半插入排序(Binary Insertion Sort)的基本思想是将新记录插入到已经 ...
随机推荐
- spring boot 开发 org.springframework.context.ApplicationContextException: Unable to start web server;
Error starting ApplicationContext. To display the conditions report re-run your application with 'de ...
- Python - WebDriver 识别登录验证码
Python - WebDriver 识别登录验证码 没什么可说的直接上代码! #-*-coding:utf-8-*- # Time:2017/9/29 7:16 # Author:YangYangJ ...
- Short Encoding of Words
2018-07-02 09:48:48 问题描述: 问题求解: 方法一.问题给了规模n = 2000,也就是说用BF在O(n^2)的时间复杂度可以过,因此,第一个方法就是BF,但是需要注意的是这里已经 ...
- 正睿 2019 省选附加赛 Day1 T1 考考试
比较奇怪的一个枚举题. 注意到10=2*5,所以10^k的二进制表示一定恰好在末尾有k个0. 考虑从小到大去填这个十进制数. 填的时候记录一下当前的二进制表示. 每次尝试去填0或者10^k. 如果要填 ...
- hdu6398 计算几何
不算严格的计算几何,就是各种分类 精度调好就能过,考虑三条边斜着放的所有情况即可 #include<bits/stdc++.h> #define LL long long #define ...
- 绝对干货!!css3字体图标—丰富的阿里图标库iconfont的使用详解
在移动端Web项目开发中,我们往往需要用到一些小图标,比如搜索,返回,小菜单,小箭头等等..这如果还用切图你就OUT了.. 而这时CSS3提供的字体图标无疑是我们最好的选择,它就像字体一样,可以设置大 ...
- OAF开发中一些LOV相关技巧 (转)
原文地址:OAF开发中一些LOV相关技巧 在OAF开发中,LOV的使用频率是很高的,它由两部分构成一是页面上的LOV输入框(如OAMESSageLovInputBean),二是弹出的LOV模式窗口(O ...
- 使用Windbg解析dump文件
WinDbg OllyDbg SoftICE (已经停止更新) 虽说WinDbg在无源码调试方面确实比较困难,但在调试内核方面却真的有独到之处. https://www.pediy.com/kssd/ ...
- customization arm ubuntu rootfs
requirment: want to get arm ubuntu rootfs method: base on debootstrap tool, customization full funct ...
- 快速切题 sgu 111.Very simple problem 大数 开平方 难度:0 非java:1
111.Very simple problem time limit per test: 0.5 sec. memory limit per test: 4096 KB You are given n ...