Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package code;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.LinkedHashMap;
- import java.util.LinkedList;
- import java.util.List;
- import java.util.Scanner;
- /**
- *
- * @author manth
- */
- public class Code {
- /**
- * @param args the command line arguments
- */
- /*
- Given a string s and a non-empty string p, find all the start indices of p's anagrams in s.
- Strings consists of lowercase English letters only and the length of both strings s and p will not be larger than 20,100.
- The order of output does not matter.
- Example 1:
- Input:
- s: "cbaebabacd" p: "abc"
- Output:
- [0, 6]
- Explanation:
- The substring with start index = 0 is "cba", which is an anagram of "abc".
- The substring with start index = 6 is "bac", which is an anagram of "abc".
- */
- static int [][] sc=new int [25][25];
- public static void main(String[] args) {
- Scanner sc1=new Scanner(System.in);
- String s=sc1.nextLine();
- floodfill(20,20);
- for(int i=0;i<max_r;i++)
- {
- for(int j=0;j<max_c;j++)
- {
- System.out.print(sc[i][j]);
- }
- System.out.println();
- }
- }
- static int color=25;
- static int max_r=sc.length;
- static int max_c=sc[0].length;
- static boolean scr[][]=new boolean[25][25];
- public static void floodfill(int r,int c)
- {
- if(r>=max_r|r<=-1|c>=max_c|c<=-1)
- {
- // System.out.println("returned");
- return;
- }
- // System.out.println(r+" "+c);
- if(scr[r][c]==true)
- return;
- sc[r][c]=color;
- scr[r][c]=true;
- floodfill(r-1,c);
- floodfill(r-1,c-1);
- floodfill(r-1,c+1);
- floodfill(r,c-1);
- floodfill(r,c+1);
- floodfill(r,c);
- floodfill(r+1,c-1);
- floodfill(r+1,c);
- floodfill(r+1,c+1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment