public class Main public static void main String args throws FileNotFo

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public class Main {
public static void main(String[] args) throws FileNotFoundException{
Scanner in = new Scanner(new File(args[0]));
ArrayList<String> initialStrings = new ArrayList<String>();
ArrayList<String> resultStrings = new ArrayList<String>();
int n = in.nextInt();
while (in.hasNext()) {
initialStrings.add(in.nextLine());
}
// main cycle start
while (n != 0) {
int max = 0, index = 0;
for (int i = 0; i < initialStrings.size(); i++) {
if (initialStrings.get(i).length() > max) {
max = initialStrings.get(i).length();
index = i;
}
}
resultStrings.add(initialStrings.get(index));
initialStrings.remove(index);
n--;
}
main cycle end
for (String s : resultStrings) { System.out.println(s); }
}
}