题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4722
## 题目
If we sum up every digit of a number and the result can be exactly divided by 10, we say this number is a good number.
You are required to count the number of good numbers in the range from A to B, inclusive.
## Input
The first line has a number T (T <= 10000) , indicating the number of test cases.
Each test case comes with a single line with two numbers A and B (0 <= A <= B <= 10
18).
## Output
For test case X, output "Case #X: " first, then output the number of good numbers in a single line.
Sample Input
2
1 10
1 20
Sample Output
Case #1: 0
Case #2: 1
Hint
The answer maybe very large, we recommend you to use long long instead of int.
## 题目大意:
就是给你两个数m,n,让你求从m到n的数中,有多少个满足各个数位上的数之和是10的倍数。
思路:如果你仔细的观察,你会发现除非是个一位数,不然每10位有一个符合要求的数,例
如:10~20有19,20~30有28.......等等,那么1到n 就应该有n/10-1给左右(不一个是这
个)我们还要判断n这个数,如果n/10*10到n有符合条件的,那么我们要做原来的n/10-1上
再+1;那么1~n的我们知道了,1~m我们也可以同理找到,相减就是我们要找的答案。
~~*我用的是直接相减的方法*~~
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int a[20];
int c,sum=0;
void sw(long long q)
{
memset(a,0,sizeof(a));
c=1;
while(q)
{
a[c++]=q%10;
q/=10;
}
return;
}
int main()
{
int t,u=1;
scanf("%d",&t); int k=0,z=0;
while(t--)
{
long long m,n;
k=0,z=0;
sum=0;
scanf("%lld%lld",&m,&n);
sw(m);
for(int i=2;i<c;i++)
{
sum+=a[i];
}
for(int i=a[1];i<=9;i++)
{
int s=sum+i;
if(s%10==0)
{
k=1;
break;
}
}
sw(n);
sum=0;
for(int i=2;i<c;i++)
{
sum+=a[i];
}
for(int i=a[1]+1;i<=9;i++)
{
int s=sum+i;
if(s%10==0)
{
z=-1;
break;
}
}
// printf("%d %d \n",k,z);
long long ans=n/10+k+z-m/10;
printf("Case #%d: ",u++);
printf("%lld\n",ans);
}
return 0;
}