fork download
  1. #include<stdio.h>
  2. #include<string.h>
  3. char ip[1009][1009],input[1009];
  4. int hash[1009][30],h2[30];
  5. int main()
  6. {
  7. int test,n;
  8. scanf("%d",&test);
  9. while(test--)
  10. {
  11. scanf("%d",&n);
  12. for(int i=0;i<n;i++)
  13. {
  14. for(int j=0;j<26;j++)
  15. h2[j]=hash[i][j]=0;
  16. }
  17. for(int i=0;i<n;i++)
  18. {
  19. scanf("%s",ip[i]);
  20. int len=strlen(ip[i]);
  21. for(int j=0;j<len;j++)
  22. {
  23. hash[i][ip[i][j]-'a']++;
  24. }
  25. }
  26. scanf("%s",input);
  27. int len=strlen(input);
  28. for(int i=0;i<len;i++)
  29. h2[input[i]-'a']++;
  30. for(int i=0;i<n;i++)
  31. {
  32. int found=1;
  33. for(int j=0;j<len;j++)
  34. {
  35. if(hash[i][input[j]-'a']<h2[input[j]-'a'])
  36. {
  37. found=0;
  38. break;
  39. }
  40. }
  41. if(found)
  42. printf("%s ",ip[i]);
  43. }
  44. if(test)
  45. printf("\n");
  46.  
  47. }
  48. return 0;
  49. }
Success #stdin #stdout 0s 4256KB
stdin
3
3
blue green yellow
el
1
q
qq
3
black blue white
lb
stdout
blue yellow 

black blue