Advertisement
Guest User

birthdate

a guest
Feb 28th, 2015
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.84 KB | None | 0 0
  1.  
  2. import java.io.*;
  3. import java.util.*;
  4.  
  5. /**
  6.  *
  7.  * @author omar
  8.  */
  9. public class Main {
  10.  
  11.     public static void main(String args[]) throws IOException {
  12.  
  13.         Reader.init(System.in);
  14.         int t = Reader.nextInt();
  15.         String[] name = new String[t];
  16.         int day[] = new int[t], mounth[] = new int[t], year[] = new int[t];
  17.         for (int i = 0; i < t; i++) {
  18.             name[i] = Reader.next();
  19.             day[i] = Reader.nextInt();
  20.             mounth[i] = Reader.nextInt();
  21.             year[i] = Reader.nextInt();
  22.  
  23.         }
  24.         String smallest = name[0];
  25.         for (int i = 0; i < t; i++) {
  26.             for (int j = 0; j < t; j++) {
  27.                 if (i == j) {
  28.                     continue;
  29.                 }
  30.                 if (year[j] > year[i]) {
  31.                     smallest = name[j];
  32.                 } else if (year[j] == year[i]) {
  33.                     if (mounth[j] > mounth[i]) {
  34.                         smallest = name[j];
  35.                     } else if (mounth[j] == mounth[i]) {
  36.                         if (day[j] > day[i]) {
  37.                             smallest = name[j];
  38.                         }
  39.                     }
  40.                 }
  41.             }
  42.  
  43.         }
  44.         String biggest = name[0];
  45.         for (int i = 0; i < t; i++) {
  46.             for (int j = 0; j < t; j++) {
  47.                 if (i == j) {
  48.                     continue;
  49.                 }
  50.                 if (year[j] < year[i]) {
  51.                     biggest = name[j];
  52.                 } else if (year[j] == year[i]) {
  53.                     if (mounth[j] < mounth[i]) {
  54.                         biggest = name[j];
  55.                     } else if (mounth[j] == mounth[i]) {
  56.                         if (day[j] < day[i]) {
  57.                             biggest = name[j];
  58.                         }
  59.                     }
  60.                 }
  61.             }
  62.  
  63.         }
  64.         System.out.println(smallest);
  65.         System.out.print(biggest);
  66.  
  67.     }
  68.  
  69. }
  70.  
  71. class Reader {
  72.  
  73.     static BufferedReader reader;
  74.     static StringTokenizer tokenizer;
  75.  
  76.     /**
  77.      * call this method to initialize reader for InputStream
  78.      */
  79.     static void init(InputStream input) {
  80.         reader = new BufferedReader(
  81.                 new InputStreamReader(input));
  82.         tokenizer = new StringTokenizer("");
  83.     }
  84.  
  85.     /**
  86.      * get next word
  87.      */
  88.     static String next() throws IOException {
  89.         while (!tokenizer.hasMoreTokens()) {
  90.             //TODO add check for eof if necessary
  91.             tokenizer = new StringTokenizer(
  92.                     reader.readLine());
  93.         }
  94.         return tokenizer.nextToken();
  95.     }
  96.  
  97.     static int nextInt() throws IOException {
  98.         return Integer.parseInt(next());
  99.     }
  100.  
  101.     static double nextDouble() throws IOException {
  102.         return Double.parseDouble(next());
  103.     }
  104.  
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement