Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.InputStreamReader;
  3. import java.util.ArrayList;
  4. import java.util.Arrays;
  5.  
  6. public class Main {
  7.  
  8. public static void main(String[] args) throws Exception{
  9. BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  10. String[] normal = br.readLine().split("");
  11. String[] reverse = new String [normal.length];
  12. int swap = 0;
  13. for(int i=0;i<normal.length;i++){
  14. reverse[i] = normal[normal.length-i-1];
  15. }
  16.  
  17. out: for(int i=0;i<normal.length;i++){
  18. if(normal[i].equals(reverse[i])){
  19. continue out;
  20. }
  21. else{
  22. for(int x=i+1;x<normal.length;x++){
  23. if(normal[x].equals(reverse[i])){
  24. for(int b = i+1;b<=x;b++) {
  25. normal[b] = normal[b - 1];
  26. swap++;
  27. }
  28. normal[i] = reverse[i];
  29. continue out;
  30. }
  31. }
  32. }
  33. }
  34. System.out.println (swap);
  35.  
  36. }
  37.  
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement