【HDOJ】4278 Faulty Odomete

水题。

 1 /* 4278 */
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cstdlib>
 5 
 6 #define MAXN 10
 7 
 8 int a[MAXN][MAXN];
 9 
10 void init() {
11     int i, j, k;
12     
13     a[0][0] = a[0][1] = a[0][2] = 0;
14     a[0][3] = a[0][4] = a[0][5] = a[0][6] = a[0][7] = 1;
15     a[0][8] = a[0][9] = 2;
16     
17     for (i=1,k=10; i<MAXN; ++i,k*=10) {
18         a[i][0] = a[i-1][9];
19         for (j=1; j<MAXN; ++j) {
20             if (j == 3 || j==8) {
21                 a[i][j] = a[i][j-1] + k;
22             } else {
23                 a[i][j] = a[i][j-1] + a[i][0];
24             }
25         }
26     }
27 }
28 
29 int main() {
30     int n, m;
31     int i, j, k;
32     int ans;
33     
34     #ifndef ONLINE_JUDGE
35         freopen("data.in", "r", stdin);
36         freopen("data.out", "w", stdout);
37     #endif
38     
39     init();
40     while (scanf("%d", &n)!=EOF && n) {
41         ans = m = n;
42         i = 0;
43         while (n) {
44             k = n%10;
45             if (k)
46                 ans -= a[i][k-1];
47             n /= 10;
48             ++i;
49         }
50         printf("%d: %d\n", m, ans);
51     }
52     
53     return 0;
54 }

 

posted on 2014-12-27 20:18  Bombe  阅读(112)  评论(0编辑  收藏  举报

导航