Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Ejemplo
  4. {
  5.  
  6.  
  7.  
  8. public static void main(String[] args)
  9. {
  10. String word = "hola";
  11. String wholeUni = "hola aloh halo laho ola ddfa daffadfadkjl adrerjlkj arqerhkaf adlfkhlkehrolahdfa rqerq adlkfhalk";
  12.  
  13. char[] seq = wholeUni.toCharArray();
  14. Set<Integer> hash_Set = new HashSet<Integer>();
  15.  
  16. String copy =new String(word);
  17. int total = word.length();
  18. boolean isEmpty = true;
  19.  
  20. for(int i = 0; i < seq.length; i++){
  21.  
  22. if(copy.length() >= 0){
  23. isEmpty = false;
  24. int idx = copy.indexOf(seq[i]);
  25.  
  26. if(idx >= 0){
  27. total--;
  28. copy = copy.substring(0, idx) + copy.substring(idx + 1);
  29. }else{
  30.  
  31. total = word.length();
  32. copy = word;
  33. }
  34. }
  35. if(total == 0 && !isEmpty){
  36. System.out.println(i - (word.length() -1) + " " + i );
  37. }
  38.  
  39. }
  40.  
  41. /*
  42. indexof y tratar de meterlos en un set,
  43. si falla es que es una letra repetida
  44. remover
  45. */
  46.  
  47. }
  48. public static String sortString(String inputString)
  49. {
  50. char tempArray[] = inputString.toCharArray();
  51. Arrays.sort(tempArray);
  52. return new String(tempArray);
  53. }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement