Algorithm Learning (1), algorithm Learning (
1. Maximum of array (insert Sorting Algorithm)
Returns the maximum and minimum values of an array.
1 input data:2 1 3 5 7 9 11 ... 295 297 299 300 298 296 ... 12 10 8 6 4 23 4 answer:5 300 1
Sort by insert Sorting Algorithm:
1 Array = [27871,-16173,-31511,-13095,301 59,-55191,-15285,143 94, 69666,-17640, -20828,450 00] 2 3 for j in range (1, len (Array )): 4 key = Array [j] 5 I = j-1 6 while I> = 0 and Array [I]> key: 7 Array [I + 1] = Array [I] 8 I = I-1 9 Array [I + 1] = key10 11 print (Array [len (Array)-1], end = '') 12 print (Array [0], end = '')
# Output: 69666-55191
2. Vowel Count (nested loop)
Description: string processing. several lines of text are provided to calculate the number of metachinar letters in each line of text. (Vowel:A, o, u, I, e, y) Note:Y is also included in this task.
1 input data:2 43 abracadabra4 pear tree5 o a kak ushakov lil vo kashu kakao6 my pyx7 8 answer:9 5 4 13 2
Use multiple for loops to solve the problem.
1 texts = ['abracadaba', 2 'pear tree', 3 'o a kak ushakov lil vo kashu kakao ', 4 'my pyx'] 5 6 letters = ['A', 'O', 'U', 'I', 'E', 'E ', 'y'] 7 8 for I in range (len (texts): 9 total = 010 for letter in letters: 11 for n in range (len (texts [I]): 12 if texts [I] [n] = letter: 13 total + = 114 print (total, end = '')
Output: 5 4 13 2