• Codeforce 141A


    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".

    题解:将一二句合并,并与第三句进行排序比较

     1 #include <iostream>
     2 #include <algorithm>
     3 #include <cstring>
     4 #include <cstdio>
     5 #include <vector>
     6 #include <cstdlib>
     7 #include <iomanip>
     8 #include <cmath>
     9 #include <ctime>
    10 #include <map>
    11 #include <set>
    12 using namespace std;
    13 #define lowbit(x) (x&(-x))
    14 #define max(x,y) (x>y?x:y)
    15 #define min(x,y) (x<y?x:y)
    16 #define MAX 100000000000000000
    17 #define MOD 1000000007
    18 #define pi acos(-1.0)
    19 #define ei exp(1)
    20 #define PI 3.141592653589793238462
    21 #define INF 0x3f3f3f3f3f
    22 #define mem(a) (memset(a,0,sizeof(a)))
    23 typedef long long ll;
    24 const int N=205;
    25 const int mod=1e9+7;
    26 char a[N],c[N];
    27 char b[N];
    28 int main()
    29 {
    30     mem(a);
    31     mem(b);
    32     mem(c);
    33     scanf("%s%s%s",&a,&b,&c);
    34     int m=strlen(a);
    35     int n=strlen(b);
    36     int l=strlen(c);
    37     int flag=1;
    38     if(l<m+n) flag=0;
    39     for(int i=m;i<n+m;i++){
    40         a[i]=b[i-m];
    41     }
    42     sort(a,a+n+m);
    43     sort(c,c+l);
    44     for(int i=0;i<l;i++){
    45         if(a[i]!=c[i]){
    46             flag=0;
    47             break;
    48         }
    49     }
    50     if(flag) cout<<"YES"<<endl;
    51     else cout<<"NO"<<endl;
    52     return 0;
    53 }

    网上的另一种写法:字符串排序,简单调用。 sort(a.begin(),a.end());

     1 #include<iostream>  
     2 #include<string>  
     3 #include<algorithm>  
     4 using namespace std;  
     5 int main()  
     6 {  
     7     string a,b,c;  
     8     cin>>a>>b>>c;  
     9     a+=b;  
    10     sort(a.begin(),a.end());  
    11     sort(c.begin(),c.end());  
    12     if(a==c)  
    13         printf("YES
    ");  
    14     else  
    15         printf("NO
    ");  
    16     return 0;  
    17 }  
  • 相关阅读:
    (转)C# 泛型委托 Action<>和Func<>
    (转)ASP.NET Core 中间件与筛选器
    react中将svg做成icon组件在其他模块调用
    react简单的tab切换 (styled-components)
    计算购物车金额总和( jquery )
    js分享功能(微信,QQ,微博,空间,豆瓣等)
    AJAX入门介绍
    作为前端,你不得不知道的搜索引擎优化
    微信小程序实现图片双滑缩放大小
    swiper实现一个好看的轮播图
  • 原文地址:https://www.cnblogs.com/wydxry/p/7259459.html
Copyright © 2020-2023  润新知