17. There is a string consisting of upper and lower cases. Now you need to modify it and place all the lower-case letters in it before the acknowledgment letter (the original order is not required between the upper and lower-case letters)

Source: Internet
Author: User
/*************************************** * String consisting of uppercase and lowercase letters, now, you need to modify the name and place all the lower-case letters in front of the acknowledgment letter (the original order is not required between the upper and lower-case letters ), if possible, the time and space efficiency should be selected as much as possible. Algorithm   C Language Function prototype void proc (char * Str) you can also use the language you are familiar *//***************************** **************************************** * ** // use the segmentation concept O (n) in quick sorting) void proc (char * Str) {int length = strlen (STR); int I = 0, j = 0; // [I, j) is always uppercase (; j <length; j ++) {If (STR [J]> = 'A' & STR [J] <= 'Z ') // lower case {swap (STR [I], STR [J]); I ++ ;}}// the second version of the segment, higher time efficiency void proc1 (char * Str) {int length = strlen (STR); int I = 0, j = length-1; // [0, I) lower case, (J, length-1] uppercase while (1) {While (I <J & STR [I] <= 'Z' & STR [I]> = 'A') ++ I; while (j> I & STR [J]> = 'A' & STR [J] <= 'Z') -- J; if (I <j) {swap (STR [I ++], STR [j --]);} elsebreak;} void testofproc () {char STR [] = "asdfdfadafsdf "; proc (STR); cout <STR <Endl; char str1 [] = "asdfdfadafsdf"; proc1 (str1); cout <str1 <Endl ;}

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.