fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7.  
  8. public class Main
  9. {
  10. private static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  11. //private static StreamTokenizer in = new StreamTokeniser();
  12. //private static Scanner in = new Scanner(System.in);
  13.  
  14. public static void main (String[] args) throws java.lang.Exception
  15. {
  16. StringBuilder a;
  17. a = new StringBuilder(in.readLine());
  18. int j = 0;
  19. boolean isSpace = false;
  20. if(a.length() == 0) System.exit(0);
  21. for(int i = 0; i < a.length(); i++){
  22. if(a.charAt(i) == ' '){
  23. if(!isSpace){
  24. isSpace = true;
  25. a.setCharAt(j,a.charAt(i));
  26. j++;
  27. }
  28. }
  29. else{
  30. isSpace = false;
  31. a.setCharAt(j,a.charAt(i));
  32. j++;
  33. }
  34. }
  35. a.delete(j, a.length());
  36. if(a.charAt(a.length() - 1) == ' ') a.delete(a.length() - 1, a.length());
  37. System.out.println(a);
  38. }
  39. }
  40.  
Success #stdin #stdout 0.11s 320576KB
stdin
 Leonardo                             was, and                             is,                                         renowned                               primarily                         as a                             painter.
stdout
 Leonardo was, and is, renowned primarily as a painter.