/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
class RangeData implements Iterable<Data>{
private Data inicio;
private Data fim;
public RangeData(Data inicio, Data fim) {
this.inicio = inicio;
this.fim = fim;
}
@Override
public Iterator<Data> iterator() {
return new Iterator<Data>() {
Data corrente = inicio;
@Override
public boolean hasNext() {
return corrente.menorOuIgual(fim);
}
@Override
public Data next() {
Data atual = corrente;
corrente = corrente.proximoDia();
return atual;
}
};
}
}
class Data {
private int dia;
private int mes;
private int ano;
public Data(){
}
public Data(int dia, int mes, int ano){
setData(dia, mes, ano);
}
public void setData(int dia, int mes, int ano){
this.dia = dia;
this.mes = mes;
this.ano = ano;
}
public boolean menorOuIgual(Data data) {
return ano < data.ano || (ano == data.ano && mes < data.mes) ||
(ano == data.ano && mes == data.mes && dia <= data.dia);
}
public Data proximoDia(){
return new Data(dia + 1, mes, ano);
}
@Override
return String.
format("%02d/%02d/%d",dia, mes, ano
); }
}
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
{
Data d[] = { new Data(), new Data(), new Data(), new Data() };
d[0].setData( 2, 4, 2016 );
d[1].setData( 12, 3, 2006 );
d[2].setData( 3, 3, 2006 );
d[3].setData( 7, 9, 2015 );
for( Data x : (new RangeData( d[2], d[1] )) )
}
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgpjbGFzcyBSYW5nZURhdGEgaW1wbGVtZW50cyBJdGVyYWJsZTxEYXRhPnsKICAgIHByaXZhdGUgRGF0YSBpbmljaW87CiAgICBwcml2YXRlIERhdGEgZmltOwoKICAgIHB1YmxpYyBSYW5nZURhdGEoRGF0YSBpbmljaW8sIERhdGEgZmltKSB7CiAgICAgICAgdGhpcy5pbmljaW8gPSBpbmljaW87CiAgICAgICAgdGhpcy5maW0gPSBmaW07CiAgICB9CgogICAgQE92ZXJyaWRlCiAgICBwdWJsaWMgSXRlcmF0b3I8RGF0YT4gaXRlcmF0b3IoKSB7CiAgICAgICAgcmV0dXJuIG5ldyBJdGVyYXRvcjxEYXRhPigpIHsKICAgICAgICAgICAgRGF0YSBjb3JyZW50ZSA9IGluaWNpbzsKICAgICAgICAgICAgQE92ZXJyaWRlCiAgICAgICAgICAgIHB1YmxpYyBib29sZWFuIGhhc05leHQoKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gY29ycmVudGUubWVub3JPdUlndWFsKGZpbSk7CiAgICAgICAgICAgIH0KCiAgICAgICAgICAgIEBPdmVycmlkZQogICAgICAgICAgICBwdWJsaWMgRGF0YSBuZXh0KCkgewogICAgICAgICAgICAgICAgRGF0YSBhdHVhbCA9IGNvcnJlbnRlOwogICAgICAgICAgICAgICAgY29ycmVudGUgPSBjb3JyZW50ZS5wcm94aW1vRGlhKCk7CiAgICAgICAgICAgICAgICByZXR1cm4gYXR1YWw7CiAgICAgICAgICAgIH0KICAgICAgICB9OwogICAgfQp9CgpjbGFzcyBEYXRhIHsKICAgIHByaXZhdGUgaW50IGRpYTsKICAgIHByaXZhdGUgaW50IG1lczsKICAgIHByaXZhdGUgaW50IGFubzsKCiAgICBwdWJsaWMgRGF0YSgpewoKICAgIH0KCiAgICBwdWJsaWMgRGF0YShpbnQgZGlhLCBpbnQgbWVzLCBpbnQgYW5vKXsKICAgICAgICBzZXREYXRhKGRpYSwgbWVzLCBhbm8pOwogICAgfQoKICAgIHB1YmxpYyB2b2lkIHNldERhdGEoaW50IGRpYSwgaW50IG1lcywgaW50IGFubyl7CiAgICAgICAgdGhpcy5kaWEgPSBkaWE7CiAgICAgICAgdGhpcy5tZXMgPSBtZXM7CiAgICAgICAgdGhpcy5hbm8gPSBhbm87CiAgICB9CgogICAgcHVibGljIGJvb2xlYW4gbWVub3JPdUlndWFsKERhdGEgZGF0YSkgewogICAgICAgIHJldHVybiBhbm8gPCBkYXRhLm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