-
Title Description:
-
Kiss!! Our foreign friend YZ has not slept well these days , junior high School Olympiad has a problem has been troubled him , hereby he sent to Jobdu to help the letter, hope that the pro can help him. The question is: Find out the number of occurrences of 1 in an integer of 1~13 , and calculate the number of occurrences of 1 in an integer of 100~1300 ? For that, he counted a few times. 1~13 contains 1 of the numbers are 1,10,11,12,13 So there is a total of 6 , but for the latter problem he can not do. Acmer wants you to help him , and to make the problem more common , you can quickly find out the number of occurrences of 1 in any nonnegative integer interval.
-
Input:
-
Enter multiple sets of data , one row per set of test data.
Each line has two integers , a, B (0<=a,b<=1,000,000,000).
-
Output:
-
For each test case , the number of occurrences of 1 between output A and B .
-
Sample input:
-
0 51 1321) 5531 99
-
Sample output:
-
1647
-
Answering:
-
problem solving problems? to discuss the subject of discussion please visit: http://t.jobdu.com/thread-8096-1-1.html
1#include <iostream>2#include <algorithm>3 using namespacestd;4 5 intA, B;6 7 intGetOne (intN) {8 intCNT =0;9 intm =N;Ten int Base=1; One while(M >0) { ACNT + = m/Ten*Base; - if(m%Ten>1) { -CNT + =Base; the}Else if(m%Ten==1) { -CNT + = n%Base+1; - } -M/=Ten; + Base*=Ten; - } + returnCNT; A } at - intMain () { - while(Cin >> a >>b) { - if(A >b) Swap (A, b); -cout << GetOne (b)-GetOne (A-1) <<Endl; - } in return 0; - } to + /************************************************************** - problem:1373 the user:hupo250 * language:c++ $ result:acceptedPanax Notoginseng time:40 Ms - memory:1520 KB the ****************************************************************/
[JOBDU] Topic 1373: Number of occurrences in integers 1 (number of occurrences from 1 to n integers 1)