Advertisement
Ruhan_DIU

Untitled

Sep 29th, 2018
116
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.io.BufferedReader;
  2. //import java.io.IOException;
  3. //import java.io.InputStreamReader;
  4. import java.util.Arrays;
  5. import java.util.Scanner;
  6.  
  7. //import static sun.nio.ch.IOStatus.EOF;
  8.  
  9. public class Main {
  10.  
  11. public static void main(String[] args){
  12. Scanner in=new Scanner(System.in);
  13. // InputStreamReader es=new InputStreamReader(System.in);
  14. // BufferedReader br=new BufferedReader(es);
  15.  
  16.  
  17. int o=in.nextInt();
  18. for (int e = 0; e < o; e++) {
  19. String sen=in.nextLine();
  20. String[] word=sen.split(" ");
  21. int[] temp=new int[word.length];
  22.  
  23. for (int i = 0; i <word.length ; i++) {
  24. temp[i]=word[i].length();
  25. }
  26.  
  27. Arrays.sort(temp);
  28. int[] check=new int[temp.length];
  29. int count,k=-1;
  30. for (int i = 0; i < temp.length; i++) {
  31. count=0;
  32. for (int j = 0; j < check.length; j++) {
  33. if(temp[i]==check[j]){
  34. count++;
  35. }
  36. }
  37.  
  38. if(count==0){
  39. k++;
  40. check[k]=temp[i];
  41. }
  42. }
  43.  
  44. Arrays.sort(check);
  45. String[] nwword=new String[word.length];
  46. k=-1;
  47. for (int i =((check.length)-1); i >=0 ; i--) {
  48. for (int j = 0; j <word.length ; j++) {
  49. if(word[j].length()==check[i]){
  50. k++;
  51. nwword[k]=word[j];
  52. }
  53. }
  54. }
  55.  
  56. for (int i = 0; i <nwword.length ; i++) {
  57. System.out.print(nwword[i]);
  58. if(i!=((nwword.length)-1)){
  59. System.out.print(" ");
  60. }
  61. }
  62. System.out.println();
  63. }
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement