Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- /**
- *
- * @author omar
- */
- public class Main {
- public static void main(String args[]) throws IOException {
- Reader.init(System.in);
- int t = Reader.nextInt();
- String[] name = new String[t];
- int day[] = new int[t], mounth[] = new int[t], year[] = new int[t];
- for (int i = 0; i < t; i++) {
- name[i] = Reader.next();
- day[i] = Reader.nextInt();
- mounth[i] = Reader.nextInt();
- year[i] = Reader.nextInt();
- }
- String smallest = name[0];
- for (int i = 0; i < t; i++) {
- for (int j = 0; j < t; j++) {
- if (i == j) {
- continue;
- }
- if (year[j] > year[i]) {
- smallest = name[j];
- } else if (year[j] == year[i]) {
- if (mounth[j] > mounth[i]) {
- smallest = name[j];
- } else if (mounth[j] == mounth[i]) {
- if (day[j] > day[i]) {
- smallest = name[j];
- }
- }
- }
- }
- }
- String biggest = name[0];
- for (int i = 0; i < t; i++) {
- for (int j = 0; j < t; j++) {
- if (i == j) {
- continue;
- }
- if (year[j] < year[i]) {
- biggest = name[j];
- } else if (year[j] == year[i]) {
- if (mounth[j] < mounth[i]) {
- biggest = name[j];
- } else if (mounth[j] == mounth[i]) {
- if (day[j] < day[i]) {
- biggest = name[j];
- }
- }
- }
- }
- }
- System.out.println(smallest);
- System.out.print(biggest);
- }
- }
- class Reader {
- static BufferedReader reader;
- static StringTokenizer tokenizer;
- /**
- * call this method to initialize reader for InputStream
- */
- static void init(InputStream input) {
- reader = new BufferedReader(
- new InputStreamReader(input));
- tokenizer = new StringTokenizer("");
- }
- /**
- * get next word
- */
- static String next() throws IOException {
- while (!tokenizer.hasMoreTokens()) {
- //TODO add check for eof if necessary
- tokenizer = new StringTokenizer(
- reader.readLine());
- }
- return tokenizer.nextToken();
- }
- static int nextInt() throws IOException {
- return Integer.parseInt(next());
- }
- static double nextDouble() throws IOException {
- return Double.parseDouble(next());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement