1 #include<stdio.h>
2 #include<string.h>
3 #include<algorithm>
4 #include<math.h>
5 using namespace std;
6 bool cmp(int a,int b)
7 {
8 return a>b;
9 }
10 int main()
11 {
12 int record1(int n);
13 int n,m;
14 while(scanf("%d%d",&n,&m),n||m)
15 {
16 if(n>m)
17 {
18 int t=n;n=m;m=t;
19 }
20 printf("%d
",record1(m)-record1(n-1));
21 }
22 return 0;
23 }
24 int record1(int n)
25 {
26 if(n<=0)
27 return 0;
28 int lnum,rnum,num,sum=0,flag=1;
29 while(n/flag!=0)
30 {
31 rnum=n-(n/flag)*flag;
32 num=(n/flag)%10;
33 lnum=n/(flag*10);
34 switch(num)
35 {
36 case 0: sum+=lnum*flag; break;
37 case 1: sum+=lnum*flag+rnum+1; break;
38 default :sum+=(lnum+1)*flag; break;
39 }
40 flag*=10;
41 }
42 return sum;
43 }
继续运用编程之美中讲过的规律搞定