Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class Solution {
  5.  
  6.  
  7. public static void main(String[] args) {
  8. Scanner in = new Scanner(System.in);
  9. String s = in.next();
  10. String result = "";
  11. if(s.length()==1)
  12. System.out.println(s);
  13. else {
  14. for(int i=0; i<s.length(); i++){
  15. if((i<s.length()-1)&&(s.charAt(i)==s.charAt(i+1)))
  16. i++;
  17. else if(result.charAt(result.length()-1)==s.charAt(i)){
  18. if(result.length()==1)
  19. result = "";
  20. else
  21. result = result.substring(0, result.length());
  22. }
  23. else
  24. result+=s.charAt(i);
  25. }
  26. }
  27. if(result.equals(""))
  28. System.out.println("Empty String");
  29. else
  30. System.out.println(result);
  31. }
  32.  
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement