这个题就比较简单了,也是去年B组的一题。
循环一边,依次判断。
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
class Main {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter pw = new PrintWriter(System.out);
public static void main(String []args) throws IOException {
int n = Integer.parseInt(br.readLine());
long res = 0;
for (int i = 1; i <= n; i++)
if (check(i))
res += i;
pw.print(res);
pw.flush();
pw.close();
br.close();
}
private static boolean check(int u) {
String temp = String.valueOf(u);
for (int i = 0; i < temp.length(); i++)
if (temp.charAt(i) == '2' || temp.charAt(i) == '0' || temp.charAt(i) == '1' || temp.charAt(i) == '9')
return true;
return false;
}
}