问题描述
本题为填空题,只需要算出结果后,在代码中使用输出语句将所填结果输出即可。
2022年2月22日22:20是一个很有意义的时间,年份为2022,由3个2和1个0组成,如果将月和日写成4位,为0222,也是由3个2和1个0组成,如果将时间中的时和分写成4位,还是由3个2和1个0组成。
小蓝对这样的时间很感兴趣,他还找到了其它类似的例子,比如111年10月11日01:11,2202年2月22日22:02等等。
请问,总共有多少个时间是这种年份写成4位、月日写成4位、时间写成4位后由3个一种数字和1个另一种数字组成。注意1111年11月11日11: 11不算,因为它里面没有两种数字。
运行限制
- 最大运行时间:1s
- 最大运行内存: 256M
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int ans = 0;
for (int i = 0; i < 10; i++) {//出现一次的数
for (int j = 0; j < 10; j++) {//出现三次的数
if (i == j) {
continue;
}
int[] aa = new int[4];
int a = 0, b = 0, c = 0;
for (int k = 0; k < 4; k++) {
for (int s = 0; s < 4; s++) {
if (k == s) {
aa[s] = i;
} else {
aa[s] = j;
}
}
a++;
int sum = aa[0] * 1000 + aa[1] * 100 + aa[2] * 10 + aa[3];
int m = sum / 100, d = sum % 100;
if (1 <= m && m <= 12 && 1 <= d && d <= 30) {
b++;
}
if (0 <= m && m <= 23 && 0 <= d && d <= 59) {
c++;
}
}
ans = ans + a * b * c;
}
}
System.out.println(ans);
scan.close();
}
}
博客围绕蓝桥杯相关问题展开,提出一个特殊时间组合的计算问题。要求找出年份写成4位、月日写成4位、时间写成4位后由3个一种数字和1个另一种数字组成的时间总数,同时给出了运行限制,最大运行时间1s,最大运行内存256M。
1669

被折叠的 条评论
为什么被折叠?



