题解 | #挑7#
挑7
https://www.nowcoder.com/practice/ba241b85371c409ea01ac0aa1a8d957b
import java.util.Scanner; import java.util.*; import java.util.regex.Pattern; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); int s1 = input.nextInt(); HashSet<Integer> hashSet = new HashSet<>(); for (int i = 1; i <= s1; i++) { String s2 = String.valueOf(i); Pattern p1 = Pattern.compile("7+"); if (i % 7 == 0) { hashSet.add(i); } else if (p1.matcher(s2).find()) { hashSet.add(i); } } System.out.println(hashSet.size()); } }