Advertisement
unknown_0711

Untitled

Oct 20th, 2022
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. public class Main{
  5. public static void main(String[] args){
  6. Scanner sc=new Scanner(System.in);
  7. int n=sc.nextInt();
  8. String s=sc.next();
  9. int m=sc.nextInt();
  10. String p=sc.next();
  11. HashMap<Character, Integer> a= new HashMap<>();
  12. HashMap<Character, Integer> b= new HashMap<>();
  13. for(int i=0;i<m;i++){
  14. b.put(p.charAt(i),b.getOrDefault(p.charAt(i),0)+1 );
  15. }
  16. if(m>n) return ;
  17. for(int i=0;i<m;i++)
  18. {
  19. a.put(s.charAt(i),a.getOrDefault(s.charAt(i),0)+1 );
  20. }
  21. boolean k=true;
  22. char c='a';
  23. for(int j=0;j<26;j++){
  24. if(a.get(c)!=b.get(c))k=false;
  25. c++;
  26. }
  27. if(k)
  28. System.out.print(0+" ");
  29.  
  30. for(int i=m;i<n;i++){
  31. a.put(s.charAt(i),a.getOrDefault(s.charAt(i),0)+1 );
  32. a.put(s.charAt(i-m),a.getOrDefault(s.charAt(i-m),0)-1 );
  33. k=true;
  34. c='a';
  35. for(int j=0;j<26;j++){
  36. if(a.getOrDefault(c,0)!=b.getOrDefault(c,0))k=false;
  37. // if(j==9)System.out.println(c+" "+ a.getOrDefault(c,0)+" "+b.getOrDefault(c,0));
  38. c++;
  39. }
  40. if(k)
  41. System.out.print(i-m+1+" ");
  42. }
  43.  
  44. }
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement