Alphabet Cookies

Alphabet Cookies

 

Problem Description

Kitty likes cookies very much, and especially the alphabet cookies. Now, she get some alphabet cookies, and she wants to select some of them to spell some words.
The easy task for you, is to determine that whether she can spell the word she wants.

Input

The input contains several test cases.
Each test case contains an integer N ( 0 < N ≤ 100 ) in a line.
And followed a line with N capital letters, means the cookies she has.
Then the last line is a word with capital letters. And the word’s length isn’t more than N.

Output

One word for each test case. If she can spell the word by these letters, please output “Yes”, nor output “No”.

Sample Input

7
ARDHPYP
HAPPY
6
ARDHPY
HAPPY

Sample Output

Yes
No

描述:

题目的大意是: 这个英文名的小朋友就假设叫 小黄 吧,这个小黄喜欢吃字母饼干,然后呢又有点喜欢做白日梦,觉得如果把字母饼干拼成一个单词,然后吃进去就可以记住这个单词了。他怕是 哆啦A梦看多了,以为是记忆面包。

所以呢,题目先告诉你现在有7个字母饼干,然后问你,可以不可以拼成下面的单词。这个题目就容易了呀,就是判断下面的字母集合是不是上面的字母集合。想怎么来都可以。用map,set.或者数组,下标表示字母,值表示当前字母个数。

Alphabet Cookies
 1 #include<bits/stdc++.h>
 2 
 3 using namespace std;
 4 const int N = 110;
 5 
 6 int main() {
 7   int n;
 8   char str[N], check_str[N];
 9   int words[1000];
10   while (cin >> n) {
11     memset(words, 0, sizeof(words));
12     cin >> str;
13     cin >> check_str;
14     for (int i = 0; i < strlen(str); i++) {
15       words[str[i]]++;
16     }
17 
18     int tp = 0;
19     for (int i = 0; i < strlen(check_str); i++) {
20       if (words[check_str[i]] > 0) {
21         words[check_str[i]] --;
22       } else {
23         tp = 1;
24         break;
25       }
26     }
27 
28     if (tp) printf("No\n");
29     else printf("Yes\n");
30   }
31   return 0;
32 }
View Code

 

上一篇:1048 Find Coins (25 分)


下一篇:poj 2230