Description
The digital difference of a positive number is constituted by the difference between each and 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 be there lying in the given interval [a, b].
Input
There is multiple cases. Each case contains 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) Test instructions: A number, the difference between the two numbers to make a new number, continue, if the result is 7, then the number of July. e.g. 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
These are the July numbers. Give an interval, and ask this interval for several July numbers.
Solution: Vector container +dfs. Starting from 7, reverse backwards. Find the number of satisfied, find the order of the container, talk about the interval inserted into the container, want to return the address difference, that is, the number. Do not save the front 0, just save the answer. For example, 7, used to generate a length of 3, 7 can be regarded as 07, just temp = x/pp[n-1];x-= temp*pp[n-1], it can be seen as a predecessor 0. Re-DFS, each time +-difference the corresponding bit value.
#include <cstdio>#include <cmath>#include <cstring>#include <algorithm>#include <iostream>#include <vector>using namespace STD; vector<int>Ans vector<int>Vintpp[]={1,Ten, -, +,10000,100000,1000000,10000000,100000000};voidDFS (intLenintXintIintTest//Several numbers, a number that meets the criteria, the first digit is what, the new number is generated{test=test*Ten+i;if(len==-1) {v.push_back (test);return; }intTemp=x/pp[len]; X=x-temp*pp[len];if(i-temp>=0) DFS (len-1, x,i-temp,test);if(i+temp<=9) DFS (len-1, x,i+temp,test);}voidFuck () {ans.push_back (7);//Bar 7 get in the container. intLen,j;intI,k; for(len=1;len<9; len++)//This number is a couple of digits{v.clear ();//Empty the V container. for(i=1; i<=9; i++)//Enumerate first digit//0 not considered{ for(k=0; K<ans.size (); k++)//ans.size () The number of elements in the//ans container{DFS (len-1, Ans[k],i,0); }} Ans.insert (Ans.end (), V.begin (), V.end ());//Put V's head to tail--add to the back of ansSort (Ans.begin (), Ans.end ());//Sort, ans head to feedAns.erase (Unique (Ans.begin (), Ans.end ()), Ans.end ());//unique (Ans.begin (), Ans.end ())//bar the same element to get back, return to the first address of the same element //ans.erase (A, B)//delete the element between A and B}}intMain () {fuck ();intb;//freopen ("A.txt", "w", stdout); while(scanf("%d%d", &a,&b)!=eof) { vector<int>:: Iterator X=lower_bound (Ans.begin (), Ans.end (), a);//Insert a into the container no smaller than a vector<int>:: Iterator Y=upper_bound (Ans.begin (), Ans.end (), b);//Put B in the container no bigger than B printf("%d\n", y-x);/ * Vector<int>::iterator i; For (I=ans.begin (); i<y;i++) printf ("%d", *i); * /}return 0;}/*1 1000287 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*/
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
July number zoj3436