Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package s_est_la_examinie;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.Comparator;
- import java.util.Date;
- import java.util.Iterator;
- import javax.management.modelmbean.RequiredModelMBean;
- public class D {
- private static final File fileIn = new File("input.txt");
- private static final File fileOut = new File("output.txt");
- private static final ArrayList<Person> list = new ArrayList<Person>();
- private static boolean noPeopleWithLessThanRequiredWeight = true;
- public static void main(String[] args) throws IOException {
- long time = new Date().getTime();
- //
- run();
- //
- System.out.println("----------------------------");
- System.out.println(new Date().getTime() - time + " ms");
- }
- private static void run() throws IOException {
- BufferedReader in = new BufferedReader(new FileReader(fileIn));
- PrintWriter out = new PrintWriter(new FileWriter(fileOut));
- byte N = Byte.parseByte(in.readLine());
- for (int i = 0; i < N; i++) {
- String[] msg = in.readLine().split(" ");
- int weight = Integer.parseInt(msg[3]);
- if (weight <= Person.REQIERED_WEIGHT) noPeopleWithLessThanRequiredWeight = false;
- Person man = new Person(msg[0], msg[1], Integer.parseInt(msg[2]), weight);
- list.add(man);
- }
- in.close();
- Collections.sort(list, Person.HEIGHT_WEIGHT_NAME_SURNAME_COMPARATOR);
- for (int i = 0; i < list.size(); i++) {
- Person p = list.get(i);
- if (noPeopleWithLessThanRequiredWeight) {
- out.println(p);
- } else {
- if (p.weight <= Person.REQIERED_WEIGHT) out.println(p);
- }
- }
- out.close();
- }
- }
- class Person {
- public static final int REQIERED_HEIGHT = 180;
- public static final int REQIERED_WEIGHT = 75;
- public static final Comparator<Person> HEIGHT_WEIGHT_NAME_SURNAME_COMPARATOR = new Comparator<Person>() {
- @Override
- public int compare(Person o1, Person o2) {
- if (Math.abs(o1.height - REQIERED_HEIGHT) > Math.abs(o2.height - REQIERED_HEIGHT)) return 1;
- else if (o1.height != o2.height) return -1;
- else if (Math.abs(o1.weight - REQIERED_WEIGHT) > Math.abs(o2.weight - REQIERED_WEIGHT)) return 1;
- else if (o1.weight != o2.weight) return -1;
- else if (o1.name.compareTo(o2.name) > 0) return 1;
- else if (!o1.name.equals(o2.name)) return -1;
- else if (o1.surname.compareTo(o2.surname) > 0) return 1;
- else if (!o1.surname.equals(o2.surname)) return -1;
- else return 0;
- }
- };
- String name, surname;
- int height, weight;
- public Person(String name, String surname, int height, int weight) {
- this.name = name;
- this.surname = surname;
- this.height = height;
- this.weight = weight;
- }
- public String toString() {
- return name + " " + surname + " " + height + " " + weight;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement