前面俩简单一点,后面看着好像还是决赛题,咕咕咕了,继续dp去了
合法日期
题目链接:https://www.lanqiao.cn/problems/541/learning/
直接读入然后判断就行,签到题
如果需要判断任一年的话只需要额外判断是不是闰年然后修改
maxDay
数组中的2月的日期就行
package daily;
import java.util.Scanner;
/**
* https://www.lanqiao.cn/problems/541/learning/
*
* @author Jia
*
*/
public class day3_26_1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();
int n = sc.nextInt();
sc.close();
// 判断月份是否超出限制
if (m > 12) {
System.out.println("no");
return;
}
// 判断日期是否超出限制
int[] maxDay = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
if (n > maxDay[m - 1]) {
System.out.println("no");
return;
}
System.out.println("yes");
}
}
古堡算式
题目链接:https://www.lanqiao.cn/problems/733/learning/
这个直接遍历所有的五位数,然后判断乘一位数字之后与其反转是否相同就可以了,我这里为了省点时间复杂度就把判断重复和反转放在一起了,如果传入数字中有重复的数字,则返回-1,否则才返回反转的数字
package daily;
import java.util.HashSet;
import java.util.Set;
/**
* https://www.lanqiao.cn/problems/733/learning/
*
* @author Jia
*/
public class day3_26_2 {
public static void main(String[] args) {
for (int i = 12345; i < 98766; i++) {
for (int j = 1; j < 10; j++) {
if (i * j == reverse(i)) {
System.out.println(i);
return;
}
}
}
}
/**
* 将传入的数字反转,如果传入数字中有重复的数字,则返回-1
*
* @param i
* @return
*/
private static int reverse(int i) {
int val = 0;
Set<Integer> set = new HashSet<>();
while (i > 0) {
int num = i % 10;
val = val * 10 + num;
i /= 10;
set.add(num);
}
return set.size() == 5 ? val : -1;
}
}
估计人数
题目链接:http://lx.lanqiao.cn/problem.page?gpid=T2740
蓝跳跳
题目链接:http://lx.lanqiao.cn/problem.page?gpid=T2872