有没有大佬愿意分享下AC的代码啊?自己太菜了,想学习一下大佬们的代码。
我就只A了第一题,逆序数那个,代码如下:
import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); long n = in.nextLong(); List<long[]> ans = new LinkedList<>(); for (long i = 1; i <= n; i++) { valid(i, ans, n); } System.out.println(ans.size()); for (long[] nums : ans) { System.out.println(nums[0] + " " + nums[1]); } } private static void valid(long num, List<long[]> ans, long max) { long num2 = num * 4; if (num2 > max) return; String n1 = String.valueOf(num); String n2 = new StringBuilder(String.valueOf(num2)).reverse().toString(); if (!n1.equals(n2)) return; ans.add(new long[]{num, num2}); } }
全部评论
(0) 回帖