Guest User

Untitled

a guest
Dec 13th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3. import java.math.*;
  4.  
  5. public class Main {
  6. private BufferedReader in;
  7. private PrintWriter out;
  8. private StringTokenizer st;
  9. private Random rnd;
  10.  
  11. class Record implements Comparable<Record> {
  12. String date, data;
  13. int a, b, c, id;
  14.  
  15. Record(String _date, String _data, int _a, int _b, int _c, int _id) {
  16. date = _date;
  17. data = _data;
  18. a = _a;
  19. b = _b;
  20. c = _c;
  21. id = _id;
  22. }
  23.  
  24. public int compareTo(Record o) {
  25. int c1 = this.a - o.a;
  26. int c2 = this.b - o.b;
  27. int c3 = this.c - o.c;
  28. int c4 = this.id - o.id;
  29.  
  30. if(c1 != 0) {
  31. return c1;
  32. }
  33.  
  34. if(c2 != 0) {
  35. return c2;
  36. }
  37.  
  38. if(c3 != 0) {
  39. return c3;
  40. }
  41.  
  42. return c4;
  43. }
  44. }
  45.  
  46. public void solve() throws IOException {
  47. ArrayList<Record> v = new ArrayList<Record>();
  48.  
  49. int id = 0;
  50.  
  51. while(true) {
  52. String line = in.readLine();
  53.  
  54. if(line == null) {
  55. break;
  56. }
  57.  
  58. String[] parts = line.split("\t");
  59. String[] date_parts = parts[0].split("\\.");
  60.  
  61. v.add(new Record(parts[0], parts[1], Integer.parseInt(date_parts[2]), Integer.parseInt(date_parts[1]), Integer.parseInt(date_parts[0]), id++));
  62. }
  63.  
  64. Collections.sort(v);
  65.  
  66. for(Record r : v) {
  67. out.println(r.date + "\t" + r.data);
  68. }
  69. }
  70.  
  71. public static void main(String[] args) {
  72. new Main().run();
  73. }
  74.  
  75. public void run() {
  76. try {
  77. //System.setIn(new FileInputStream("rating.in"));
  78. //System.setOut(new PrintStream(new FileOutputStream("rating.out")));
  79.  
  80. in = new BufferedReader(new InputStreamReader(System.in));
  81. out = new PrintWriter(System.out);
  82. st = null;
  83. rnd = new Random();
  84.  
  85. solve();
  86.  
  87. out.close();
  88. } catch(IOException e) {
  89. e.printStackTrace();
  90. }
  91. }
  92.  
  93. private String nextToken() throws IOException, NullPointerException {
  94. while(st == null || !st.hasMoreTokens()) {
  95. st = new StringTokenizer(in.readLine());
  96. }
  97.  
  98. return st.nextToken();
  99. }
  100.  
  101. private int nextInt() throws IOException {
  102. return Integer.parseInt(nextToken());
  103. }
  104.  
  105. private long nextLong() throws IOException {
  106. return Long.parseLong(nextToken());
  107. }
  108.  
  109. private double nextDouble() throws IOException {
  110. return Double.parseDouble(nextToken());
  111. }
  112.  
  113. }
Add Comment
Please, Sign In to add comment