fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. class Ideone {
  5. public static void main (String[] args) throws java.lang.Exception {
  6. Scanner in = new Scanner(System.in);
  7. String word;
  8. String words[] = new String[256];
  9. char table[] = new char[256];
  10. int count[] = new int[256];
  11. int tempcount[] = new int[256];
  12. int templength,length,sum = 0,kilk,countwords = 0;
  13. int mem = 0, index = 0;
  14. word = in.nextLine();
  15. kilk = in.nextInt();
  16. for (int i = 0; i < kilk+1; i++) {
  17. words[i] = in.nextLine();
  18. }
  19. length = word.length();
  20. table[0] = word.charAt(0);
  21. for (int i = 1; i < length; i++) {
  22. for (int j = 0; j < i; j++) {
  23. if (word.charAt(i) == table[j])
  24. mem = 1;
  25. }
  26. if (mem == 0) {
  27. index++;
  28. table[index] = word.charAt(i);
  29. }
  30. mem = 0;
  31. }
  32. mem = 0;
  33. for (int i = 0; i <= index; i++) {
  34. for (int j = 0; j < length; j++) {
  35. if (table[i] == word.charAt(j)) {
  36. mem++;
  37. }
  38. }
  39. count[i] = mem;
  40. mem = 0;
  41. }
  42. int mem2 = 0;
  43. for (int a = 0; a < kilk; a++) {
  44. templength = words[a].length();
  45. mem = 0;
  46. for (int i = 0; i <= index; i++) {
  47. for (int j = 0; j < templength; j++) {
  48. if (table[i] == words[a].charAt(j)) mem++;
  49. }
  50. tempcount[i] = mem;
  51. mem = 0;
  52. }
  53. for (int i = 0; i <= index; i++) sum = sum + tempcount[i];
  54. mem2 = 0;
  55. if (sum == templength) {
  56. for (int i = 0; i <= index; i++) {
  57. if (tempcount[i]>count[i])mem2++;
  58. }
  59. if (mem2 == 0) countwords++;
  60. }
  61. sum = 0;
  62. }
  63. System.out.println(countwords);
  64. }
  65. }
Success #stdin #stdout 0.13s 29404KB
stdin
приветствие
8
ветер
треск
спирт
трепет
перерыв
север
текст
привести
stdout
5