Advertisement
unknown_0711

Untitled

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