Faulty Odometer
time limit per test 1 second memory limit per test 256 megabytes
You are given a car odometer which displays the miles traveled as an integer. The odometer has a defect, however: it proceeds from the digit 2 to the digit 4 and from the digit 7 to the digit 9, always skipping over the digit 3 and 8. This defect shows up in all positions (the one’s, the ten’s, the hundred’s, etc.). For example, if the odometer displays 15229 and the car travels one mile, odometer reading changes to 15240 (instead of 15230).

传送门:HDU4278

Input

Each line of input contains a positive integer in the range 1..999999999 which represents an odometer reading. (Leading zeros will not appear in the input.) The end of input is indicated by a line containing a single 0. You may assume that no odometer reading will contain the digit 3 and 8.

Output

Each line of input will produce exactly one line of output, which will contain: the odometer reading from the input, a colon, one blank space, and the actual number of miles traveled by the car.

Sample Input

1
2
3
4
5
6
15
2005
250
1500
999999
0

Sample Output

1
2
3
4
5
15: 12
2005: 1028
250: 160
1500: 768
999999: 262143

题解

我的实力终于能达到一秒秒题的境界了 这问题转化一下 不就是求1-n中有多少个不含3或8的数嘛 数位dp裸题
## AC code:(不包含输入类)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import java.io.*;  
import java.util.*;
public class Main {
static int[][]dp;
public static void main(String[] args) {
FastScanner sc=new FastScanner();
PrintWriter pw=new PrintWriter(System.out);
while(sc.hasNext()){
int n=sc.nextInt();
if(n==0)break;
dp=new int[12][10];
dp[0][0]=1;
for(int i=1;i<=10;i++){
for(int j=0;j<=9;j++){
for(int k=0;k<=9;k++){
if(j!=3&&j!=8){
dp[i][j]+=dp[i-1][k];
}
}
}
}
pw.println(n+": "+js(n));
pw.flush();
}

}
static int js(int t){
int count=0;
String s=String.valueOf(t);
for(int i=0;i<s.length();i++){
for(int k=0;k<(s.charAt(i)-'0');k++){
if(k!=3&&k!=8)
count+=dp[s.length()-i][k];
}
if(s.charAt(i)=='3'||s.charAt(i)=='8')break;
}
return count;
}
}