1462: Alphabet Cookies
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
HINT
简单题 储存判断就好了 好多种写法思路
Code:
#include<stdio.h>
#include<string.h>
int main()
{
int n;
char a[105],b[105];
int x[30];
while(~scanf("%d",&n))
{
memset(x,0,sizeof(x));
scanf("%s %s",a,b);
for(int i=0;i<strlen(a);i++)
x[a[i]-'A']++;
int f=1;
for(int i=0;i<strlen(b);i++)
x[b[i]-'A']--;
for(int i=0;i<30;i++)
{
if(x[i]<0)
{
f=0;
break;
}
}
if(f)printf("Yes\n");
else printf("No\n");
}
return 0;
}