Advertisement
anasretdinov

UuUuY

Apr 4th, 2020
436
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.54 KB | None | 0 0
  1. import java.util.*;
  2. import java.lang.Math;
  3. public class Main{
  4.     static Scanner s = new Scanner(System.in);
  5.     public static void main (String[] args) {
  6.         int t = s.nextInt();
  7.         for (int jnbth = 0; jnbth < t; jnbth++) {
  8.             String s1 = s.next();
  9.             int year = Integer.parseInt(s1.substring(6,s1.length()-1));
  10.             int day = Integer.parseInt(s1.substring(0, 2));
  11.             int month = Integer.parseInt(s1.substring(3, 5))-1;
  12.             Date d = new Date(year, month, day);
  13.             for (int i = year; i < 10000; i++) {
  14.                 if (d.before(palin(i))){
  15.                     System.out.println(palin(i).getDay()+"." + palin(i).getMonth()+"." + palin(i).getYear()); break;
  16.                 }
  17.             }
  18.         }
  19.     }
  20.     static public Date palin(int year){
  21.         String y = ""+(year / 1000 + '0') + (year / 100 % 10 + '0') + (year / 10 % 10 + '0') + (year % 10 + '0');
  22.         Date dt = new Date (0, Calendar.JANUARY,0);
  23.         String monn = reverse(y.substring(0,2));
  24.         String dd = reverse(y.substring(3));
  25.         return new Date(year, Integer.parseInt(monn), Integer.parseInt(dd));
  26.     }
  27.     static String reverse(String s){
  28.         String s1 = "";
  29.         for (int i = s.length()-1; i > -1; i--) {
  30.             s1 += s.charAt(i);
  31.         }
  32.         return s1;
  33.     }
  34. }
  35. class Data implements Comparable<Data>{
  36.     int year = 0;
  37.     int day = 1;
  38.     int month = 1;
  39.     Data(int day, int month, int year){
  40.         this.year = year;
  41.         this.month = month;
  42.         this.day = day;
  43.     }
  44.     Data(String s1){
  45.         int year = Integer.parseInt(s1.substring(6,s1.length()-1));
  46.         int day = Integer.parseInt(s1.substring(0, 2));
  47.         int month = Integer.parseInt(s1.substring(3, 5));
  48.         this.year = year;
  49.         this.month = month;
  50.         this.day = day;
  51.     }
  52.  
  53.     @Override
  54.     public int compareTo(Data data) {
  55.         if (this.year == data.year){
  56.             if (this.month==data.month) return this.day-data.day; else return this.month-data.month;
  57.         }
  58.         else{
  59.             return this.year - data.year;
  60.         }
  61.     }
  62.     void print(){
  63.         String d = ""+(day/10+'0') + (day % 10+'0');
  64.         String y = ""+(year / 1000 + '0') + (year / 100 % 10 + '0') + (year / 10 % 10 + '0') + (year % 10 + '0');
  65.         String m =  ""+(month/10+'0') + (month % 10+'0');
  66.         System.out.println(y + "." + m + "." + d + ".");
  67.     }
  68. }
  69. class Pair{
  70.     int x;
  71.     int y;
  72.     Pair(int x, int y){
  73.         this.x = x;
  74.         this.y = y;
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement