Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.lang.Math;
- public class Main{
- static Scanner s = new Scanner(System.in);
- public static void main (String[] args) {
- int t = s.nextInt();
- for (int jnbth = 0; jnbth < t; jnbth++) {
- String s1 = s.next();
- int year = Integer.parseInt(s1.substring(6,s1.length()-1));
- int day = Integer.parseInt(s1.substring(0, 2));
- int month = Integer.parseInt(s1.substring(3, 5))-1;
- Date d = new Date(year, month, day);
- for (int i = year; i < 10000; i++) {
- if (d.before(palin(i))){
- System.out.println(palin(i).getDay()+"." + palin(i).getMonth()+"." + palin(i).getYear()); break;
- }
- }
- }
- }
- static public Date palin(int year){
- String y = ""+(year / 1000 + '0') + (year / 100 % 10 + '0') + (year / 10 % 10 + '0') + (year % 10 + '0');
- Date dt = new Date (0, Calendar.JANUARY,0);
- String monn = reverse(y.substring(0,2));
- String dd = reverse(y.substring(3));
- return new Date(year, Integer.parseInt(monn), Integer.parseInt(dd));
- }
- static String reverse(String s){
- String s1 = "";
- for (int i = s.length()-1; i > -1; i--) {
- s1 += s.charAt(i);
- }
- return s1;
- }
- }
- class Data implements Comparable<Data>{
- int year = 0;
- int day = 1;
- int month = 1;
- Data(int day, int month, int year){
- this.year = year;
- this.month = month;
- this.day = day;
- }
- Data(String s1){
- int year = Integer.parseInt(s1.substring(6,s1.length()-1));
- int day = Integer.parseInt(s1.substring(0, 2));
- int month = Integer.parseInt(s1.substring(3, 5));
- this.year = year;
- this.month = month;
- this.day = day;
- }
- @Override
- public int compareTo(Data data) {
- if (this.year == data.year){
- if (this.month==data.month) return this.day-data.day; else return this.month-data.month;
- }
- else{
- return this.year - data.year;
- }
- }
- void print(){
- String d = ""+(day/10+'0') + (day % 10+'0');
- String y = ""+(year / 1000 + '0') + (year / 100 % 10 + '0') + (year / 10 % 10 + '0') + (year % 10 + '0');
- String m = ""+(month/10+'0') + (month % 10+'0');
- System.out.println(y + "." + m + "." + d + ".");
- }
- }
- class Pair{
- int x;
- int y;
- Pair(int x, int y){
- this.x = x;
- this.y = y;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement