Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //import java.io.BufferedReader;
- //import java.io.IOException;
- //import java.io.InputStreamReader;
- import java.util.Arrays;
- import java.util.Scanner;
- //import static sun.nio.ch.IOStatus.EOF;
- public class Main {
- public static void main(String[] args){
- Scanner in=new Scanner(System.in);
- // InputStreamReader es=new InputStreamReader(System.in);
- // BufferedReader br=new BufferedReader(es);
- int o=in.nextInt();
- for (int e = 0; e < o; e++) {
- String sen=in.nextLine();
- String[] word=sen.split(" ");
- int[] temp=new int[word.length];
- for (int i = 0; i <word.length ; i++) {
- temp[i]=word[i].length();
- }
- Arrays.sort(temp);
- int[] check=new int[temp.length];
- int count,k=-1;
- for (int i = 0; i < temp.length; i++) {
- count=0;
- for (int j = 0; j < check.length; j++) {
- if(temp[i]==check[j]){
- count++;
- }
- }
- if(count==0){
- k++;
- check[k]=temp[i];
- }
- }
- Arrays.sort(check);
- String[] nwword=new String[word.length];
- k=-1;
- for (int i =((check.length)-1); i >=0 ; i--) {
- for (int j = 0; j <word.length ; j++) {
- if(word[j].length()==check[i]){
- k++;
- nwword[k]=word[j];
- }
- }
- }
- for (int i = 0; i <nwword.length ; i++) {
- System.out.print(nwword[i]);
- if(i!=((nwword.length)-1)){
- System.out.print(" ");
- }
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement