1463: Alphabet Cookies
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 72 Solved: 37
Submit Status Web Board
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
7ARDHPYPHAPPY6ARDHPYHAPPY
Sample Output
YesNo
HINT
Source
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<string>
using namespace std;
int main()
{
int N,i,j,lena,lenb,jihao,flag[110];
char a[110],b[110];
while(scanf("%d",&N)!=EOF)
{
jihao=0;
memset(flag,0,sizeof(flag));
cin>>a>>b;
lenb=strlen(b);
lena=strlen(a);
for(i=0;i<lenb;i++)//5
{
for(j=0;j<lena;j++)//7
{
if(b[i]==a[j] && !flag[j])
{
flag[j]=1;
jihao++;
break;
}
}
}
if(jihao==lenb)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
return 0;
}
/**************************************************************
Problem: 1463
User: CuiHuiling
Language: C++
Result: Accepted
Time:3 ms
Memory:1328 kb
****************************************************************/