Prohause

Untitled

Apr 24th, 2016
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /**
  4. * Created by proha on 23.4.2016 г..
  5. */
  6. public class Problem1 {
  7. public static void main(String[] args) {
  8. Scanner scanner = new Scanner(System.in);
  9.  
  10. String input = scanner.nextLine();
  11. String toMatch = scanner.nextLine();
  12.  
  13. int first;
  14. int second;
  15.  
  16. first = input.indexOf(toMatch);
  17. second = input.lastIndexOf(toMatch);
  18. boolean match = (first != second && first >= 0 && second >= 0);
  19.  
  20. while (match) {
  21. input = input.substring(0,first) + input.substring(first+toMatch.length(),second) + input.substring(second+toMatch.length(),input.length());
  22. //current = new StringBuilder(input);
  23. //current = new StringBuilder(current.replace(second, second + toMatch.length(), ""));
  24. //current = new StringBuilder(current.replace(first, first + toMatch.length(), ""));
  25. //input = current.toString();
  26. System.out.println("Shaked it.");
  27. if (toMatch.length()>2){
  28. toMatch = toMatch.substring(0,toMatch.length()/2)+toMatch.substring(toMatch.length()/2+1,toMatch.length());
  29. }
  30. else if (toMatch.length()==2){
  31. toMatch = toMatch.substring(0,1);
  32. }
  33. else {
  34. break;
  35. }
  36. /* char[] newMatch = toMatch.toCharArray();
  37. toMatch = "";
  38. for (int i = 0; i < newMatch.length; i++) {
  39. if (i != newMatch.length / 2)
  40. toMatch += newMatch[i];
  41. }*/
  42. //
  43. // System.out.println(toMatch);
  44. first = input.indexOf(toMatch);
  45. second = input.lastIndexOf(toMatch);
  46. match = first != second && first >= 0 && second >= 0;
  47. }
  48. System.out.println("No shake.");
  49. System.out.println(input);
  50.  
  51.  
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment