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 ;
}
最新文章
- No module named * 但是已经安装了找不到解决办法
- adId、idfv
- 如何调试异步加载的js文件(浏览器调试动态加载js)
- oracle得到拼音函数
- 我已提取并尝试使用启动脚本(./start navicat)来启动 Navicat Linux 版本号,但没有反应
- 翻译连载 | 第 11 章:融会贯通 -《JavaScript轻量级函数式编程》 |《你不知道的JS》姊妹篇
- linux常用命令小结
- 随笔【js】
- 利用NSE脚本检测域传送和证书透明度滥用
- swust oj 982
- sql2008r2安装失败的解决办法
- “std”: 具有该名称的命名空间不存在
- 机器学习理论基础学习17---贝叶斯线性回归(Bayesian Linear Regression)
- hdu4901The Romantic Hero
- c++学习笔记(新手学习笔记,如有错误请与作者联系)
- TCP和UDP相关概念
- js的作用域深入理解
- centos7 samba安装
- opengl键盘回调函数不能获取Ctrl+c的问题
- pdoModel封装
热门文章
- 【原创】使用HTML5+canvas+JavaScript开发的原生中国象棋游戏及源码分享
- SprinMVC接收参数乱码解决篇
- Windows环境下flask+Apache+mod_wsgi部署及爬坑
- 腾讯云:ubuntu搭建 FTP 文件服务
- 腾讯云,搭建python开发环境
- JSTL 实现 为Select赋多个值
- hadoop-hdp-ambari离线安装记录
- 【codeforces 527C】Glass Carving
- Debug : array type has incomplete element type
- hdu_1019_Least Common Multiple_201310290920