fork(8) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. static boolean compareArr(int[] countTXT,int[] countPATT)
  11. {
  12. for(int i=0; i<256; i++)
  13. {
  14. if(countTXT[i]!=countPATT[i])
  15. return false;
  16. }
  17. return true;
  18. }
  19. static void search(String patt, String txt)
  20. {
  21. int countTXT[] = new int[256];
  22. int countPATT[] = new int[256];
  23.  
  24. for(int i=0; i<patt.length(); i++)
  25. {
  26. countTXT[txt.charAt(i)]++;
  27. countPATT[patt.charAt(i)]++;
  28. }
  29. for(int i=patt.length(); i<txt.length(); i++)
  30. {
  31. if(compareArr(countTXT,countPATT)==true)
  32. System.out.print((i-patt.length())+" ");
  33.  
  34. countTXT[txt.charAt(i)]++;
  35. countTXT[txt.charAt(i-patt.length())]--;
  36. }
  37. if(compareArr(countTXT,countPATT)==true)
  38. System.out.print((txt.length()-patt.length())+" ");
  39. }
  40. public static void main (String[] args) throws java.lang.Exception
  41. {
  42. String txt = br.readLine();
  43. String patt = br.readLine();
  44. search(patt, txt);
  45. }
  46. }
Success #stdin #stdout 0.07s 380224KB
stdin
BACDGABCDA
ABCD
stdout
0 5 6