Algorithm Learning (1), algorithm Learning (

Source: Internet
Author: User

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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.