#G 特殊年份
时间限制: 1.0s 内存限制: 512.0MB 本题总分:20 分
问题描述
今年是 2021 年,2021 这个数字非常特殊,它的千位和十位相等,个位比百位大 1 ,我们称满足这样条件的年份为特殊年份。
输入 5 个年份,请计算这里面有多少个特殊年份。
输入格式
输入 5 行,每行一个 4 位十进制数(数值范围为 1000 至 9999 ),表示一个年份。
输出格式
输出一个整数,表示输入的 5 个年份中有多少个特殊年份。
测试样例1
Input:
2019
2021
1920
2120
9899
Output:
2
Explanation:
2021 和 9899 是特殊年份,其它不是特殊年份。
代码如下:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int[] a=new int[5];
for (int i = 0; i < a.length; i++) {
a[i]=sc.nextInt();
}
int sum=0;
for (int i = 0; i < a.length; i++) {
if(a[i]/10%10==a[i]/1000%10&&a[i]/100%10+1==a[i]%10) {
sum++;
}
}
System.out.println(sum);
}
}