package temp;
import java.io.*;
import java.util.Arrays;
import java.util.Comparator;
public class Test {
public static void main
(String[] args
) { Record[] records = loadRecords();
Arrays.
sort(records,
new Comparator
<Record
>() { @Override
public int compare(Record o1, Record o2) {
return o1.name.compareTo(o2.name);
}
});
saveRecords("/home/b/Desktop/sortedByName.txt", records);
Arrays.
sort(records,
new Comparator
<Record
>() { @Override
public int compare(Record o1, Record o2) {
return o1.number.compareTo(o2.number);
}
});
saveRecords("/home/b/Desktop/sortedByNumber.txt", records);
Arrays.
sort(records,
new Comparator
<Record
>() { @Override
public int compare(Record o1, Record o2) {
return Integer.
compare(o1.
score, o2.
score); }
});
saveRecords("/home/b/Desktop/sortedByScore.txt", records);
}
static void saveRecords
(String filepath, Record
[] records
) { try {
for (Record record : records) {
bw.write(record.name + " " + record.number + " " + record.score);
bw.newLine();
}
}
}
}
}
}
static Record[] loadRecords() {
try {
Record[] records = new Record[20];
for (int i = 0; i < 20; i++) {
String[] columns
= br.
readLine().
split(" "); records
[i
] = new Record
(columns
[0], columns
[1],
Integer.
parseInt(columns
[2])); }
return records;
}
}
}
}
}
}
class Record {
int score;
this.name = name;
this.number = number;
this.score = score;
}
}
cGFja2FnZSB0ZW1wOwoKaW1wb3J0IGphdmEuaW8uKjsKaW1wb3J0IGphdmEudXRpbC5BcnJheXM7CmltcG9ydCBqYXZhLnV0aWwuQ29tcGFyYXRvcjsKCnB1YmxpYyBjbGFzcyBUZXN0IHsKCiAgICBwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmdbXSBhcmdzKSB7CiAgICAgICAgUmVjb3JkW10gcmVjb3JkcyA9IGxvYWRSZWNvcmRzKCk7CgogICAgICAgIEFycmF5cy5zb3J0KHJlY29yZHMsIG5ldyBDb21wYXJhdG9yPFJlY29yZD4oKSB7CiAgICAgICAgICAgIEBPdmVycmlkZQogICAgICAgICAgICBwdWJsaWMgaW50IGNvbXBhcmUoUmVjb3JkIG8xLCBSZWNvcmQgbzIpIHsKICAgICAgICAgICAgICAgIHJldHVybiBvMS5uYW1lLmNvbXBhcmVUbyhvMi5uYW1lKTsKICAgICAgICAgICAgfQogICAgICAgIH0pOwogICAgICAgIHNhdmVSZWNvcmRzKCIvaG9tZS9iL0Rlc2t0b3Avc29ydGVkQnlOYW1lLnR4dCIsIHJlY29yZHMpOwoKICAgICAgICBBcnJheXMuc29ydChyZWNvcmRzLCBuZXcgQ29tcGFyYXRvcjxSZWNvcmQ+KCkgewogICAgICAgICAgICBAT3ZlcnJpZGUKICAgICAgICAgICAgcHVibGljIGludCBjb21wYXJlKFJlY29yZCBvMSwgUmVjb3JkIG8yKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gbzEubnVtYmVyLmNvbXBhcmVUbyhvMi5udW1iZXIpOwogICAgICAgICAgICB9CiAgICAgICAgfSk7CiAgICAgICAgc2F2ZVJlY29yZHMoIi9ob21lL2IvRGVza3RvcC9zb3J0ZWRCeU51bWJlci50eHQiLCByZWNvcmRzKTsKCiAgICAgICAgQXJyYXlzLnNvcnQocmVjb3JkcywgbmV3IENvbXBhcmF0b3I8UmVjb3JkPigpIHsKICAgICAgICAgICAgQE92ZXJyaWRlCiAgICAgICAgICAgIHB1YmxpYyBpbnQgY29tcGFyZShSZWNvcmQgbzEsIFJlY29yZCBvMikgewogICAgICAgICAgICAgICAgcmV0dXJuIEludGVnZXIuY29tcGFyZShvMS5zY29yZSwgbzIuc2NvcmUpOwogICAgICAgICAgICB9CiAgICAgICAgfSk7CiAgICAgICAgc2F2ZVJlY29yZHMoIi9ob21lL2IvRGVza3RvcC9zb3J0ZWRCeVNjb3JlLnR4dCIsIHJlY29yZHMpOwogICAgfQoKICAgIHN0YXRpYyB2b2lkIHNhdmVSZWNvcmRzKFN0cmluZyBmaWxlcGF0aCwgUmVjb3JkW10gcmVjb3JkcykgewogICAgICAgIHRyeSB7CiAgICAgICAgICAgIHRyeSAoRmlsZU91dHB1dFN0cmVhbSBmb3MgPSBuZXcgRmlsZU91dHB1dFN0cmVhbShmaWxlcGF0aCkpIHsKICAgICAgICAgICAgICAgIHRyeSAoT3V0cHV0U3RyZWFtV3JpdGVyIG9zdyA9IG5ldyBPdXRwdXRTdHJlYW1Xcml0ZXIoZm9zKSkgewogICAgICAgICAgICAgICAgICAgIHRyeSAoQnVmZmVyZWRXcml0ZXIgYncgPSBuZXcgQnVmZmVyZWRXcml0ZXIob3N3KSkgewogICAgICAgICAgICAgICAgICAgICAgICBmb3IgKFJlY29yZCByZWNvcmQgOiByZWNvcmRzKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBidy53cml0ZShyZWNvcmQubmFtZSArICIgIiArIHJlY29yZC5udW1iZXIgKyAiICIgKyByZWNvcmQuc2NvcmUpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgYncubmV3TGluZSgpOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgfSBjYXRjaCAoSU9FeGNlcHRpb24gZSkgewogICAgICAgICAgICB0aHJvdyBuZXcgUnVudGltZUV4Y2VwdGlvbihlKTsKICAgICAgICB9CiAgICB9CgogICAgc3RhdGljIFJlY29yZFtdIGxvYWRSZWNvcmRzKCkgewogICAgICAgIHRyeSB7CiAgICAgICAgICAgIFJlY29yZFtdIHJlY29yZHMgPSBuZXcgUmVjb3JkWzIwXTsKICAgICAgICAgICAgdHJ5IChGaWxlSW5wdXRTdHJlYW0gZmlzID0gbmV3IEZpbGVJbnB1dFN0cmVhbSgiL2hvbWUvYi9EZXNrdG9wL2RhdGEudHh0IikpIHsKICAgICAgICAgICAgICAgIHRyeSAoSW5wdXRTdHJlYW1SZWFkZXIgaXNyID0gbmV3IElucHV0U3RyZWFtUmVhZGVyKGZpcykpIHsKICAgICAgICAgICAgICAgICAgICB0cnkgKEJ1ZmZlcmVkUmVhZGVyIGJyID0gbmV3IEJ1ZmZlcmVkUmVhZGVyKGlzcikpIHsKICAgICAgICAgICAgICAgICAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCAyMDsgaSsrKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBTdHJpbmdbXSBjb2x1bW5zID0gYnIucmVhZExpbmUoKS5zcGxpdCgiICIpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgcmVjb3Jkc1tpXSA9IG5ldyBSZWNvcmQoY29sdW1uc1swXSwgY29sdW1uc1sxXSwgSW50ZWdlci5wYXJzZUludChjb2x1bW5zWzJdKSk7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHJlY29yZHM7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgfSBjYXRjaCAoSU9FeGNlcHRpb24gZSkgewogICAgICAgICAgICB0aHJvdyBuZXcgUnVudGltZUV4Y2VwdGlvbihlKTsKICAgICAgICB9CiAgICB9Cn0KCmNsYXNzIFJlY29yZCB7CiAgICBTdHJpbmcgbmFtZTsKICAgIFN0cmluZyBudW1iZXI7CiAgICBpbnQgc2NvcmU7CgogICAgUmVjb3JkKFN0cmluZyBuYW1lLCBTdHJpbmcgbnVtYmVyLCBpbnQgc2NvcmUpIHsKICAgICAgICB0aGlzLm5hbWUgPSBuYW1lOwogICAgICAgIHRoaXMubnVtYmVyID0gbnVtYmVyOwogICAgICAgIHRoaXMuc2NvcmUgPSBzY29yZTsKICAgIH0KfQo=