The digital difference of a positive number is constituted by the difference between each two neighboring digits (with the leading zeros omitted). For example the digital difference of 1135 is 022 = 22. The repeated digital difference, or differential root, can be obtained by caculating the digital difference until a single-digit number is reached. A number whose differential root is 7 is also called July Number. Your job is to tell how many July Numbers are there lying in the given interval [a,b].
Input
There are multiple cases. Each case contains two integers a and b. 1 ≤a ≤ b ≤ 109.
Output
One integer k, the number of July Numbers.
Sample Input
1 10
Sample Output
1
题意:(1)题意:一个数,前后两个数之差组成新数,一直下去,如果结果是7,则为7月数。如7 18 29 70 81 92 108 118 188 198 209 219 229 299 700770 780 790 801 811 881 891 902 910 912 922 980 992
这些都是7月数。给一个区间,问这个区间中有几个7月数。 题目不难,但代码实现有些麻烦。
#include<cstring>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
vector<int> ans,v;
int p[11]={0,1,10,100,1000,10000,100000,1000000,10000000,100000000};
void dfs(int len,int i,int x,int cut)
{
cut=cut*10+i;
if(len==0)
{
v.push_back(cut);
return ;
}
int tem=x/p[len];
x=x-tem*p[len];
if(i+tem<=9)dfs(len-1,i+tem,x,cut);
if(i-tem>=0)dfs(len-1,i-tem,x,cut);
}
void slove()
{
ans.push_back(7);
for(int len=1;len<9;len++)
{
v.clear();
for(int i=1;i<=9;i++)
{
for(int j=0;j<ans.size();j++)
{//cout<<" ***";
dfs(len,i,ans[j],0);
}
}
ans.insert(ans.end(),v.begin(),v.end());
sort(ans.begin(),ans.end());
ans.erase(unique(ans.begin(),ans.end()),ans.end());
}
}
int main()
{
slove();
int x,y;
while(scanf("%d%d",&x,&y)!=EOF)
{
printf("%d\n",upper_bound(ans.begin(),ans.end(),y)-lower_bound(ans.begin(),ans.end(),x));
}
return 0;
}