Codeforces Amusing Joke 题解

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.

Sample test(s)

input

SANTACLAUS
DEDMOROZ
SANTAMOROZDEDCLAUS

output

YES

input

PAPAINOEL
JOULUPUKKI
JOULNAPAOILELUPUKKI

output

NO

input

BABBONATALE
FATHERCHRISTMAS
BABCHRISTMASBONATALLEFATHER

output

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

时间: 2024-11-07 03:23:07

Codeforces Amusing Joke 题解的相关文章

codeforces Flipping Game 题解

Iahub got bored, so he invented a game to be played on paper. He writes n integers a1,?a2,?...,?an. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices i and j (1?≤?i?≤?j?≤?n) and flips all values 

codeforces The Wall - 题解

Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on. Iahub has the following scheme o

codeforces Gravity Flip 题解

Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity. There are n columns of toy cubes in the box arranged in a line. The i-th

codeforces A. TL 题解

Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it. Valera has written n correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote m 

Codeforces Unlucky Ticket 题解

Each of you probably has your personal experience of riding public transportation and buying tickets. After a person buys a ticket (which traditionally has an even number of digits), he usually checks whether the ticket is lucky. Let us remind you th

codeforces A. k-String 题解

A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string

codeforces A. Array题解

Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: The product of all numbers in the first set is less than zero (?<?0). The product of all numbers in the secon

codeforces A. Cakeminator 题解

本题思路: 1 先扫描行,如果可以吃,就数吃了多少格,然后做好标志 2 扫描列,同样处理 扫描完就可以出答案了. 时间效率是O(n*m)了.算是暴力法 题目: http://codeforces.com/problemset/problem/330/A #include <vector> #include <algorithm> #include <utility> #include <string> #include <queue> #incl

codeforces Epic Game 题解

Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number a and Antisimon receives number b. They also have a heap of nstones. The players take turns to m