-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathraggedright.java
26 lines (24 loc) · 1.04 KB
/
raggedright.java
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
import java.io.*;
import java.util.*;
import java.math.*;
public class raggedright {
public static void main(String[] args) throws Exception {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
//BufferedReader in = new BufferedReader(new FileReader("input.txt"));
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
String line = "";
ArrayList<Integer> lengths = new ArrayList<Integer>();
long sum = 0;
while((line = in.readLine()) != null) lengths.add(line.length());
//out.println(lengths);
int toRemove = lengths.get(lengths.size() - 1);
Collections.sort(lengths);
int maxLength = lengths.get(lengths.size() - 1);
lengths.remove(lengths.indexOf(toRemove));
for(int i = 0; i < lengths.size(); i++) sum += (maxLength - lengths.get(i)) * (maxLength - lengths.get(i));
//out.println(lengths);
//out.println(maxLength);
out.println(sum);
out.close();
}
}