标签:style blog color os width io
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.
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.
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.
SANTACLAUS DEDMOROZ SANTAMOROZDEDCLAUS
YES
PAPAINOEL JOULUPUKKI JOULNAPAOILELUPUKKI
NO
BABBONATALE FATHERCHRISTMAS BABCHRISTMASBONATALLEFATHER
NO
一个典型的hash表的运用。检查三个字母串是否有同样多的字母。
void AmusingJoke() { string s1, s2, s3; cin>>s1>>s2>>s3; if (s1.size() + s2.size() != s3.size()) { cout<<"NO"; return; } int A[26] = {0}; for (unsigned i = 0; i < s1.size(); i++) { A[s1[i] - ‘A‘]++; } for (unsigned i = 0; i < s2.size(); i++) { A[s2[i] - ‘A‘]++; } for (unsigned i = 0; i < s3.size(); i++) { A[s3[i] - ‘A‘]--; } bool ok = true; for (unsigned i = 0; i < 26 && ok; i++) { if (A[i] != 0) ok = false; } if (ok) cout<<"YES"; else cout<<"NO"; }
Codeforces Amusing Joke 题解,码迷,mamicode.com
标签:style blog color os width io
原文地址:http://blog.csdn.net/kenden23/article/details/24781883