Example of calculating the number of pages in a python computing book
The example in this article describes how to calculate the number of pages of a book in python. It is a typical application in Python programming. Share it with you for your reference. The details are as follows:
Problem description: for the given page number n, calculate the number of numbers 0, 1, 2, 3, 4, 9 used in all pages respectively
The instance code is as follows:
def count_num1(page_num): num_zero = 0 num_one = 0 num_two = 0 num_three = 0 num_four = 0 num_five = 0 num_six = 0 num_seven = 0 num_eight = 0 num_nine = 0 page_list = range(1,page_num + 1) for page in page_list: page = str(page) num_zero += page.count('0') num_one += page.count('1') num_two += page.count('2') num_three += page.count('3') num_four += page.count('4') num_five += page.count('5') num_six += page.count('6') num_seven += page.count('7') num_eight += page.count('8') num_nine += page.count('9') result = [num_zero,num_one,num_two,num_three,num_four,num_five,num_six,num_seven,num_eight,num_nine] return result print count_num1(13)
The code above is a little bloated, so I changed the code.
The modified code is as follows:
def count_num2(page_num): page_list = range(1,page_num + 1) result = [0 for i in range(10)] for page in page_list: page = str(page) for i in range(10): temp = page.count(str(i)) result[i] += temp return resultprint count_num2(13)
The testing environment of this example is Python2.7.6.
The program output result is:
[1, 6, 2, 2, 1, 1, 1, 1, 1]
I hope this article will help you with Python programming.
Algorithm and analysis of statistics and integer factorization
1.
# Include <stdio. h>
# Include <stdlib. h>
# Include <string. h>
# Define N 2048 // if you have more than 2048 books to calculate, you need to apply for Memory later
Void func (unsigned int (* ptr) [10], int m, int idx)
{
Int I, j, h;
For (I = 1; I <= m; ++ I) {// This for can improve efficiency through algorithms, that is, to obtain the number of 0-9 low numbers based on high numbers, the algorithm is simple.
J = I;
While (j> 0 ){
+ Ptr [idx] [j % 10];
J/= 10;
}
}
}
Int main ()
{
Unsigned int arr [2048] [10] = {0}; // Number of times each book was stored 0-9
Unsigned int (* ptr) [10] = 0;
Unsigned int m [N], n; // m [N] stores the number of pages per book
Unsigned int * m_ptr;
Unsigned int I;
Printf ("Input n (the lines of m ):");
Scanf ("% u", & n );
If (n> N) {// if there are more than 2048 books, apply for memory to save
Ptr = (unsigned int (*) [10]) malloc (n * 10 * sizeof (unsigned int ));
M_ptr = (unsigned int *) malloc (n * sizeof (unsigned int ));
}
Else {
Ptr = arr;
M_ptr = m;
}
Printf ("Input % u numbers:", n );
For (I = 0; I <n; ++ I ){
Scanf ("% u", m_ptr + I );
}
For (I = 0; I <n; ++ I) {// separate with the preceding for, which avoids disturbing the input buffer optimized by the compiler and can be merged to it.
Func (ptr, m_ptr [I], I );
}
// Output 0-9
Printf ("number: % 5u % 5u % 5u % 5u % 5u % 5u % 5u % 5u % 5u % 5u \ n", 0, 1, 2 ...... remaining full text>
Word2010 page number Rome numeric problem urgent
Divide your article into sections, use the roman numerals as a section, do not use page numbers as a section, and use numbers as a section. You can insert a subscriber to subscribe to the subscribe. Be sure to cancel "link to the previous"
1. Place the cursor at the top of the body: menu bar -- insert -- Separator Type -- continuous -- OK.
2. Menu Bar -- View -- header and footer -- (the "header and footer" floating toolbar appears) -- place the cursor in the footer, click Cancel "link to the previous one" (the button is "two parallel pages"): The "Same as the previous section" in the upper-right corner of the footer dotted box disappears.
3. Click "set page number format" (the button is "Hand and page") -- page number arrangement -- (Roman numerals) Number Format: select 1, 2, 3,... as needed ,......; Start page: modify "1" -- OK.
4. Click "insert page number" (the button is "# on paper #").
5. Close the "floating toolbar for headers and footers ".