Paragraphs are in reverse order of words.

Source: Internet
Author: User
//// In reverse order of words, the punctuation is in non-reverse order. example: // "ABC def GH. \ nabc def GH. "The Reverse Order is" GH. def ABC \ ngh. def ABC "// method: first put the letters in the sentence upside down, and then put each word letter upside down, as shown below. //. hg fed CBA \ n. hg fed CBA // GH. def ABC \ ngh. def ABC // # include <cstdlib> # include <cassert> # include <iostream> // invert word letters. // void reverse_word (char * word, size_t length) {assert (null! = Word); char ch; For (size_t I = 0; I <length/2; ++ I) {CH = word [I]; word [I] = word [length-1-I]; word [length-1-I] = CH ;}/// invert all letters in the sentence. // void reverse_sentence (char * sentence, size_t length) {size_t begin = 0; reverse_word (sentence, length); For (size_t offset = 0; offset <length; + offset) {If (''= sentence [offset]) {reverse_word (sentence + begin, offset-begin); begin = offset + 1 ;}} Rev Erse_word (sentence + begin, length-begin);} // invert the letters of all words in the paragraph. // void reverse_section (char * Section) {assert (null! = Section); // invert each sentence word. For (size_t begin = 0, offset = 0; '\ 0 '! = Section [offset]; ++ offset) {If ('\ n' = Section [offset] |' \ 0' = Section [offset]) {reverse_sentence (section + begin, offset-begin); begin = offset + 1 ;}} int main (void) {char section [] = "ABC def GH. \ nabc def GH. "; reverse_section (section); STD: cout <section <STD: Endl; return exit_success ;}

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.