import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;
import java.util.StringTokenizer;
class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
class Utility {
public static int sn(String s) {
int ret = 0;
for(int i = 0; i < s.length(); i++) {
ret *= 10;
ret += ( (s.charAt(i))-'0');
}
return ret;
}
}
class date implements Comparator<String> {
public int compare(String ca, String cb) {
String sYearA = "" + ca.charAt(4) + ca.charAt(5) + ca.charAt(6) + ca.charAt(7);
String sYearB = "" + cb.charAt(4) + cb.charAt(5) + cb.charAt(6) + cb.charAt(7);
String sMonthA = "" + ca.charAt(2) + ca.charAt(3);
String sMonthB = "" + cb.charAt(2) + cb.charAt(3);
String sDayA = "" + ca.charAt(0) + ca.charAt(1);
String sDayB = "" + cb.charAt(0) + cb.charAt(1);
int nYearA = Utility.sn(sYearA);
int nYearB = Utility.sn(sYearB);
int nMonthA = Utility.sn(sMonthA);
int nMonthB = Utility.sn(sMonthB);
int nDayA = Utility.sn(sDayA);
int nDayB = Utility.sn(sDayB);
if(nYearA==nYearB) {
if(nMonthA==nMonthB)
return Integer.compare(nDayA, nDayB);
return Integer.compare(nMonthA, nMonthB);
}
return Integer.compare(nYearA, nYearB);
}
}
class Pair implements Comparable<Pair> {
String s;
int ind;
Pair(String s, int ind) {
this.s = s;
this.ind = ind;
}
public int compareTo(Pair o) {
String ca = s;
String cb = o.s;
String sYearA = "" + ca.charAt(4) + ca.charAt(5) + ca.charAt(6) + ca.charAt(7);
String sYearB = "" + cb.charAt(4) + cb.charAt(5) + cb.charAt(6) + cb.charAt(7);
String sMonthA = "" + ca.charAt(2) + ca.charAt(3);
String sMonthB = "" + cb.charAt(2) + cb.charAt(3);
String sDayA = "" + ca.charAt(0) + ca.charAt(1);
String sDayB = "" + cb.charAt(0) + cb.charAt(1);
int nYearA = Utility.sn(sYearA);
int nYearB = Utility.sn(sYearB);
int nMonthA = Utility.sn(sMonthA);
int nMonthB = Utility.sn(sMonthB);
int nDayA = Utility.sn(sDayA);
int nDayB = Utility.sn(sDayB);
if(nYearA==nYearB) {
if(nMonthA==nMonthB)
return Integer.compare(nDayA, nDayB);
return Integer.compare(nMonthA, nMonthB);
}
return Integer.compare(nYearA, nYearB);
}
}
public class Main {
public static int cmp(String ca, String cb) {
String sYearA = "" + ca.charAt(4) + ca.charAt(5) + ca.charAt(6) + ca.charAt(7);
String sYearB = "" + cb.charAt(4) + cb.charAt(5) + cb.charAt(6) + cb.charAt(7);
String sMonthA = "" + ca.charAt(2) + ca.charAt(3);
String sMonthB = "" + cb.charAt(2) + cb.charAt(3);
String sDayA = "" + ca.charAt(0) + ca.charAt(1);
String sDayB = "" + cb.charAt(0) + cb.charAt(1);
int nYearA = Utility.sn(sYearA);
int nYearB = Utility.sn(sYearB);
int nMonthA = Utility.sn(sMonthA);
int nMonthB = Utility.sn(sMonthB);
int nDayA = Utility.sn(sDayA);
int nDayB = Utility.sn(sDayB);
if(nYearA==nYearB) {
if(nMonthA==nMonthB)
return Integer.compare(nDayA, nDayB);
return Integer.compare(nMonthA, nMonthB);
}
return Integer.compare(nYearA, nYearB);
}
public static void main(String[] args) {
int days[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
ArrayList<String> listPalindromicDates = new ArrayList<String>();
ArrayList<Pair> listDates = new ArrayList<Pair>();
for(int month = 1; month < days.length; month++) {
for(int day = 1; day <= days[month]; day++) {
String sday = String.valueOf(day);
if(sday.length()==1) sday = '0' + sday;
String smonth = String.valueOf(month);
if(smonth.length()==1) smonth = '0' + smonth;
String syear = sday + smonth;
syear = new StringBuffer(syear).reverse().toString();
listPalindromicDates.add(sday + smonth + syear);
if(month==2 && day==28) {
int new_day = day + 1;
sday = String.valueOf(new_day);
if(sday.length()==1) sday = '0' + sday;
smonth = String.valueOf(month);
if(smonth.length()==1) smonth = '0' + smonth;
syear = sday + smonth;
syear = new StringBuffer(syear).reverse().toString();
listPalindromicDates.add(sday + smonth + syear);
}
}
}
Collections.sort(listPalindromicDates, new date());
MyScanner input = new MyScanner();
int n = input.nextInt();
for(int i = 0; i < n; i++) {
String D = input.next();
D = D.replace(".", "");
listDates.add(new Pair(D, i));
}
Collections.sort(listDates);
int index = 0;
String[] sarrAnswer = new String[n];
for(int i = 0; i < listDates.size(); i++) {
while(index < listPalindromicDates.size() && (cmp(listDates.get(i).s, listPalindromicDates.get(index)) >= 0 ) ) index++;
sarrAnswer[i] = listPalindromicDates.get(index);
}
for(int i = 0; i < n; i++) {
System.out.print(sarrAnswer[i].charAt(0));
System.out.print(sarrAnswer[i].charAt(1));
System.out.print(".");
System.out.print(sarrAnswer[i].charAt(2));
System.out.print(sarrAnswer[i].charAt(3));
System.out.print(".");
System.out.print(sarrAnswer[i].charAt(4));
System.out.print(sarrAnswer[i].charAt(5));
System.out.print(sarrAnswer[i].charAt(6));
System.out.print(sarrAnswer[i].charAt(7));
System.out.println(".");
}
}
}
Compilation message
datum.java:123: error: class Main is public, should be declared in a file named Main.java
public class Main {
^
1 error