回文日期:给定一个 8 位数的日期,请你计算该日期之后下一个回文日期和下一个 ABABBABA 型的回文日期各是哪一天。

题目描述

2020 年春节期间,有一个特殊的日期引起了大家的注意:2020 年 2 月 2 日。因为如果将这个日期按 “yyyymmdd” 的格式写成一个 8 位数是 20200202,恰好是一个回文数。我们称这样的日期是回文日期。

有人表示 20200202 是 “千年一遇” 的特殊日子。对此小明很不认同,因为不到 2 年之后就是下一个回文日期:20211202 即 2021 年 12 月 2 日。

也有人表示 20200202 并不仅仅是一个回文日期,还是一个 ABABBABA 型的回文日期。对此小明也不认同,因为大约 100 年后就能遇到下一个 ABABBABA 型的回文日期:21211212 即 2121 年 12 月 12 日。算不上 “千年一遇”,顶多算 “千年两遇”。

给定一个 8 位数的日期,请你计算该日期之后下一个回文日期和下一个 ABABBABA 型的回文日期各是哪一天。

输入描述

输入包含一个八位整数 NN,表示日期。

对于所有评测用例,10000101 \leq N \leq 8999123110000101≤N≤89991231,保证 NN 是一个合法日期的 8 位数表示。

输出描述

输出两行,每行 1 个八位数。第一行表示下一个回文日期,第二行表示下一个 ABABBABA 型的回文日期。

package test01;

import java.util.Scanner;

import javafx.scene.chart.PieChart.Data;

public class Test03 {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int data = scanner.nextInt();
		huiwenriqi(data);
		ABhuiwenriqi(data);
	}
	public static void huiwenriqi (int n) {
		for (int i = n+1; i <= 89991231; i++) {
			String string = i+"";
			if (string.charAt(0)==string.charAt(7)
					&&string.charAt(1)==string.charAt(6)
					&&string.charAt(2)==string.charAt(5)
					&&string.charAt(3)==string.charAt(4)) {
				
				int years = i/10000;
                int mouth = (i/100)%100;
                int day = i%100;
				if (mouth<=12) {
					if (mouth==2) {
						if (years%4==0&&day<=29) {
							System.out.println(i);
							return;
						}else if(years%4!=0&&day<=28){
							System.out.println(i);
							return;
						}
					}else if ((mouth==1||mouth==3||mouth==5||mouth==7||mouth==8||mouth==10||mouth==12)&&day<=31) {
						System.out.println(i);
						return;
					}else if ((mouth==4||mouth==6||mouth==9||mouth==11)&&day<=30) {
						System.out.println(i);
						return;
					}
					
				}
			}
		}
	}
	
	public static void ABhuiwenriqi (int n) {
		for (int i = n+1; i <= 89991231; i++) {
			String string = i+"";
			if (string.charAt(0)==string.charAt(2)&&string.charAt(5)==string.charAt(7)&&string.charAt(2)==string.charAt(5)
				&&string.charAt(1)==string.charAt(3)&&string.charAt(3)==string.charAt(4)&&string.charAt(4)==string.charAt(6)) {
				
				int years = i/10000;
                int mouth = (i/100)%100;
                int day = i%100;
				if (mouth<=12) {
					if (mouth==2) {
						if (years%4==0&&day<=29) {
							System.out.println(i);
							return;
						}else if(years%4!=0&&day<=28){
							System.out.println(i);
							return;
						}
					}else if ((mouth==1||mouth==3||mouth==5||mouth==7||mouth==8||mouth==10||mouth==12)&&day<=31) {
						System.out.println(i);
						return;
					}else if ((mouth==4||mouth==6||mouth==9||mouth==11)&&day<=30) {
						System.out.println(i);
						return;
					}
					
				}
			}
		}
	}
	
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值