Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Scanner sc=new Scanner(System.in);
- int n=sc.nextInt();
- String s=sc.next();
- int m=sc.nextInt();
- String p=sc.next();
- HashMap<Character, Integer> a= new HashMap<>();
- HashMap<Character, Integer> b= new HashMap<>();
- for(int i=0;i<m;i++){
- b.put(p.charAt(i),b.getOrDefault(p.charAt(i),0)+1 );
- }
- if(m>n) return ;
- for(int i=0;i<m;i++)
- {
- a.put(s.charAt(i),a.getOrDefault(s.charAt(i),0)+1 );
- }
- boolean k=true;
- char c='a';
- for(int j=0;j<26;j++){
- if(a.get(c)!=b.get(c))k=false;
- c++;
- }
- if(k)
- System.out.print(0+" ");
- for(int i=m;i<n;i++){
- a.put(s.charAt(i),a.getOrDefault(s.charAt(i),0)+1 );
- a.put(s.charAt(i-m),a.getOrDefault(s.charAt(i-m),0)-1 );
- k=true;
- c='a';
- for(int j=0;j<26;j++){
- if(a.getOrDefault(c,0)!=b.getOrDefault(c,0))k=false;
- // if(j==9)System.out.println(c+" "+ a.getOrDefault(c,0)+" "+b.getOrDefault(c,0));
- c++;
- }
- if(k)
- System.out.print(i-m+1+" ");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement