HDU Good Numbers (热身赛2)

时间:2024-11-12 14:07:38

转载请注明出处:http://blog.****.net/a1dark

分析:一道水题、找下规律就OK了、不过要注意特判一下0、因为0也是good number、这个把我坑惨了= =|||

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
int main(){
__int64 a,b;
int t,step=1;
scanf("%d",&t);
while(t--){
scanf("%I64d%I64d",&a,&b);
__int64 ans;
__int64 sa,sb;
int flag=0;
if(b>=10){
__int64 s=b;
__int64 sum=0;
while(s!=0){
sum+=s%10;
s/=10;
}
sum=sum-b%10;
sum%=10;
if(sum==0 || sum+b%10>=10)
flag=0;
else
flag=1;
sb=b/10-flag;
}
else
sb=0;
flag=0;
if(a>=11){
__int64 s=a-1;
__int64 sum=0;
while(s!=0){
sum+=s%10;
s/=10;
}
sum=sum-(a-1)%10;
sum%=10;
if(sum==0 || sum+(a-1)%10>=10)
flag=0;
else
flag=1;
sa=(a-1)/10-flag;
}
else
sa=0;
if(a==0 || b==0)
sb++;
printf("Case #%d: %I64d\n",step++,sb-sa);
}
return 0;
}