File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change 1+ import java.util.Scanner;
2+ 
3+ public class QuickSort {
4+ 
5+ public static void main(String[] args) {
6+ 
7+ Scanner sc = new Scanner(System.in);
8+ 
9+ String str = sc.nextLine();
10+ String ans = "";
11+ 
12+ int spaces = 0, len = str.length()-1;
13+ 
14+ while(len>=0) {
15+ while(len >= 0 && str.charAt(len) == ' ') {
16+ len--;
17+ spaces++;
18+ }
19+ int j = len;
20+ 
21+ if(len<0) { break;}
22+ 
23+ while(len >= 0 && str.charAt(len) != ' ') {
24+ len--;
25+ }
26+ 
27+ if(ans.isEmpty()) {
28+ ans = ans.concat(str.substring(len+1,j+1));
29+ 
30+ }else {
31+ while(spaces >= 0) {
32+ if(spaces == 0) {
33+ ans = ans.concat(str.substring(len+1,j+1));
34+ break;
35+ }
36+ ans = ans.concat(" ");
37+ spaces--;
38+ }
39+ spaces = 0;
40+ }
41+ }
42+ 
43+ str = ans.toString();
44+ System.out.println(str);
45+ }
46+ 
47+ }
                         You can’t perform that action at this time. 
           
                  
0 commit comments