有多少个0 (How many 0's? ,UVa 11038)

 1 #include <iostream>
 2 #include <string.h>
 3 #include <string>
 4 #include <fstream>
 5 #include <algorithm>
 6 #include <stdio.h>
 7 #include <vector>
 8 #include <queue>
 9 #include <set>
10 #include <cmath>
11 using namespace std;
12 const double eps = 1e-8;
13 const int INF=0x7fffffff;
14 unsigned long long uINF = ~0LL;
15 #define MAXN 10000007
16 typedef long long LL;
17 LL a[11];
18 void init()
19 {
20     LL dig=10;a[0]=1;
21     for(int i=1;i<10;i++)
22     {
23         a[i]=a[i-1]*10+dig;
24         dig*=10;
25    //     cout<<a[i]<<endl;
26     }
27 }
28 string Reverse(string str1)
29 {
30     string str2="";
31     for(int i=str1.length()-1;i>=0;i--)
32     str2+=str1[i];
33     return str2;
34 }
35 LL solve(LL x)
36 {
37     LL ans=0,temp,dig=1,y=0;
38     while(x>=10)
39     {
40         temp=x%10;
41         x/=10;
42         if(temp)ans+=dig*x;
43         else ans+=dig*(x-1)+y+1;
44         y+=temp*dig;
45         dig*=10;
46     }
47     return ans;
48 }
49 int main()
50 {
51     LL m,n;
52     init();
53     while(scanf("%lld%lld",&m,&n),m+n>=0)
54     {
55         //cout<<solve(m)<<' '<<solve(n)<<endl;
56         LL ans=solve(n)-solve(m-1);
57         if(m==0)ans++;
58         printf("%lld\n",ans);
59 
60     }
61 
62     return 0;
63 }

 

posted @ 2013-07-23 17:35  TO_Asia  阅读(373)  评论(0编辑  收藏  举报