T - Amusing Joke(map)
Problem description
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. One night, when everyone went to bed, someone took all the letters of our characters' names. Then he may have shuffled the letters and put them in one pile in front of the door.
The next morning it was impossible to find the culprit who had made the disorder. But everybody wondered whether it is possible to restore the names of the host and his guests from the letters lying at the door? That is, we need to verify that there are no extra letters, and that nobody will need to cut more letters.
Help the "New Year and Christmas Men" and their friends to cope with this problem. You are given both inscriptions that hung over the front door the previous night, and a pile of letters that were found at the front door next morning.
Input
The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line does not exceed 100.
Output
Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes.
Examples
Input
SANTACLAUS
DEDMOROZ
SANTAMOROZDEDCLAUS
Output
YES
Input
PAPAINOEL
JOULUPUKKI
JOULNAPAOILELUPUKKI
Output
NO
Input
BABBONATALE
FATHERCHRISTMAS
BABCHRISTMASBONATALLEFATHER
Output
NO
Note
In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left.
In the second sample letter "P" is missing from the pile and there's an extra letter "L".
In the third sample there's an extra letter "L".
解题思路:题目的意思就是将第一行字符串和第二行的字符串中的字母随机打乱顺序并且拼接起来和第三行的字符串比较,如果第三行的字符串刚好为前两行字符串中的字母组成,则输出"YES",否则输出"NO"。做法:采用map容器,键为字母序号,值为该字母出现的次数,如果前两行每个字母出现的次数和第三行对应字母出现的次数都相同,则输出"YES",否则输出"NO",水过。
AC代码:
#include<bits/stdc++.h>
using namespace std;
int main(){
map<int,int> mp1,mp2;
for(int i=;i<;++i)mp1[i]=mp2[i]=;
char s1[],s2[],s3[];
cin>>s1>>s2>>s3;
for(int i=;s1[i]!='\0';++i)mp1[s1[i]-'A']++;
for(int i=;s2[i]!='\0';++i)mp1[s2[i]-'A']++;
for(int i=;s3[i]!='\0';++i)mp2[s3[i]-'A']++;
bool flag=false;
for(int i=;i<;++i)
if(mp1[i]!=mp2[i]){flag=true;break;}
if(flag)cout<<"NO"<<endl;
else cout<<"YES"<<endl;
return ;
}
T - Amusing Joke(map)的更多相关文章
- Codeforce 141A - Amusing Joke (sort)
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests a ...
- GO语言总结(4)——映射(Map)
上一篇博客介绍了Go语言的数组和切片——GO语言总结(3)——数组和切片,本篇博客介绍Go语言的映射(Map) 映射是一种内置的数据结构,用来保存键值对的无序集合. (1)映射的创建 make ( m ...
- Java-集合=第五题 (Map)设计Account 对象如下: private long id; private double balance; private String password; 要求完善设计,使得该Account 对象能够自动分配id。 给定一个List 如下: List list = new ArrayList(); list.add(new A
第五题 (Map)设计Account 对象如下: private long id; private double balance; private String password; 要求完善设计,使得 ...
- Java-map-第一题 (Map)利用Map,完成下面的功能: 从命令行读入一个字符串,表示一个年份,输出该年的世界杯冠军是哪支球队。如果该 年没有举办世界杯,则输出:没有举办世界杯。 附:世界杯冠军以及对应的夺冠年份,请参考本章附录。 附录
第一题 (Map)利用Map,完成下面的功能: 从命令行读入一个字符串,表示一个年份,输出该年的世界杯冠军是哪支球队.如果该 年没有举办世界杯,则输出:没有举办世界杯. 附:世界杯冠军以及对应的夺冠年 ...
- 第一题 (Map)利用Map,完成下面的功能:
从命令行读入一个字符串,表示一个年份,输出该年的世界杯冠军是哪支球队.如果该 年没有举办世界杯,则输出:没有举办世界杯. 附:世界杯冠军以及对应的夺冠年份,请参考本章附录. 附录 1.历届世界杯冠 ...
- 【机器学习基本理论】详解最大似然估计(MLE)、最大后验概率估计(MAP),以及贝叶斯公式的理解
[机器学习基本理论]详解最大似然估计(MLE).最大后验概率估计(MAP),以及贝叶斯公式的理解 https://mp.csdn.net/postedit/81664644 最大似然估计(Maximu ...
- 【机器学习基本理论】详解最大后验概率估计(MAP)的理解
[机器学习基本理论]详解最大后验概率估计(MAP)的理解 https://blog.csdn.net/weixin_42137700/article/details/81628065 最大似然估计(M ...
- GoLang基础数据类型--->字典(map)详解
GoLang基础数据类型--->字典(map)详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 可能大家刚刚接触Golang的小伙伴都会跟我一样,这个map是干嘛的,是 ...
- 列表生成式+过滤器(filter)+映射(map)+lambda总结
这些都是python的特色,不仅强大,而且好用,配合起来使用更是无敌. 零.lambda lambda用于产生一个匿名表达式,组成部分为:lambda + ‘函数表达式’ ‘函数表达式’由一个冒号加上 ...
随机推荐
- 一个ROS的服务,使机器人向前移动指定距离
源代码有点长,放文末链接里了. 服务描述及代码现在的服务是:请求时携带要前进的距离,然后底盘前进相应距离.代码如下,改动很小: #!/usr/bin/env python import rospyfr ...
- IDEA生成增强for循环
itar 生成array for代码块 for (int i = 0; i < array.length; i++) { = array[i]; } itco 生成Collection迭代 fo ...
- python利用7z批量解压rar
一开始我使用了rarfile这个库,奈何对于含有密码的压缩包支持不好,在linux上不抛出异常:之后有又尝试了unrar..比rarfile还费劲.. 所以用了调用系统命令的方法,用7z来解压 通过a ...
- enote笔记语言(3)
what&why(why not)&how&when&where&which:紫色,象征着神秘而又潜蕴着强大的力量,故取紫色. key&key-memo ...
- 7-9 旅游规划 (25 分)(Dijkstra算法)
题意: 思路:单源最短路问题,Dijkstra算法搞定就可以了,因为要找出最便宜的最短路,所以需要在更新最短距离的时候加一个条件(即当最短距离相等的时候,如果该路径的花费更小,就更新最小花费)就可 ...
- 3 numpy模块
Numpy 什么是Numpy:Numeric Python Numpy模块是Python的一种开源的数值计算扩展. 1 一个强大的N维数组对象Array ...
- class类加载机制
1.类的加载过程 a.加载-链接-初始化-使用-卸载 加载: 查找并加载类的二进制数据 链接: 验证类的正确性,为类的静态变量分配内存,并将其初始化为默认值,把类的符号引用转换为直接引用. 初始化: ...
- Surround the Trees HDU 1392 凸包
Problem Description There are a lot of trees in an area. A peasant wants to buy a rope to surround a ...
- CF #329 D
D题,LCA是很明显的.要注意的是,因为是除法,所以最多可以除x>2的有64次,当大于64时可以直接返回0.而且注意到可能会有很多值为1的边,可以使用路径压缩,把边为1的边压缩掉,类似于并查集的 ...
- 【转】storm 开发系列一 第一个程序
原文: http://blog.csdn.net/csfreebird/article/details/49104777 --------------------------------------- ...