fork download
  1. import java.util.*;
  2. import java.lang.*;
  3.  
  4. class Main
  5. {
  6. public static ArrayList<String> solve (String input, int x, int y)
  7. {
  8. int s = 0;
  9. ArrayList<String> matches = new ArrayList<String>();
  10. String segment = null;
  11.  
  12. for (int i=0; i<(input.length()-x); i++)
  13. {
  14. s = 0;
  15. segment = input.substring(i,(i+x));
  16.  
  17. System.out.print(" i: "+i+" ");
  18.  
  19. for (char c : segment.toCharArray())
  20. {
  21. System.out.print("*");
  22.  
  23. if (c == '1')
  24. {
  25. s = s + 1;
  26. }
  27. }
  28.  
  29. if (s == y)
  30. {
  31. matches.add(segment);
  32. }
  33.  
  34. System.out.println();
  35. }
  36.  
  37. return matches;
  38. }
  39.  
  40. public static void main (String [] args)
  41. {
  42. String input = "011010101001101110110110101010111011010101000110010";
  43.  
  44. int x = 6;
  45.  
  46. int y = 4;
  47.  
  48. ArrayList<String> matches = null;
  49.  
  50. matches = solve (input, x, y);
  51.  
  52. for (String match : matches)
  53. {
  54. System.out.println(" > "+match);
  55. }
  56. }
  57. }
Success #stdin #stdout 0.08s 380224KB
stdin
Standard input is empty
stdout
 i: 0 ******
 i: 1 ******
 i: 2 ******
 i: 3 ******
 i: 4 ******
 i: 5 ******
 i: 6 ******
 i: 7 ******
 i: 8 ******
 i: 9 ******
 i: 10 ******
 i: 11 ******
 i: 12 ******
 i: 13 ******
 i: 14 ******
 i: 15 ******
 i: 16 ******
 i: 17 ******
 i: 18 ******
 i: 19 ******
 i: 20 ******
 i: 21 ******
 i: 22 ******
 i: 23 ******
 i: 24 ******
 i: 25 ******
 i: 26 ******
 i: 27 ******
 i: 28 ******
 i: 29 ******
 i: 30 ******
 i: 31 ******
 i: 32 ******
 i: 33 ******
 i: 34 ******
 i: 35 ******
 i: 36 ******
 i: 37 ******
 i: 38 ******
 i: 39 ******
 i: 40 ******
 i: 41 ******
 i: 42 ******
 i: 43 ******
 i: 44 ******
 > 110101
 > 011011
 > 101110
 > 011101
 > 110110
 > 101101
 > 011011
 > 110110
 > 101101
 > 110101
 > 101011
 > 010111
 > 101110
 > 011101
 > 110110
 > 101101
 > 110101