/*******************************
pclvmm 2014-01-18 17:38
String A id include String B
*******************************/
#include
char s1[] = "ABCDEFGHIGKLMNOPQ";
char s2[] = "DCGSPQR";
char s3[] = "ABEGH";
int is_include(char *s1, char *s2)
{
int a[26] = {0,};
while(*s1 != '\0'){
a[*s1 - 'A']++;
s1++;
}
while(*s2 != '\0'){
if(a[*s2 - 'A'] == 0)
return 0;
s2++;
}
return 1;
}
int main(int argc, char ** argv)
{
if(is_include(s1, s2))
printf("true\n");
else
printf("false\n");
if(is_include(s1, s3))
printf("true\n");
else
printf("false\n");
return 0;
}
~
~
这是先建立一个26个长的的数组,然后一第一个数组进行HASH(哈希)求出来,没个字符出现的次数,然后第二个字符遍历一遍进行求解。O(M + N);