Enter an English sentence to flip the order of words in the sentence. The character sequence in the word remains unchanged.

Source: Internet
Author: User

Question: enter an English sentence to flip the order of words in the sentence, but the order of Characters in the word remains unchanged. Words in a sentence are separated by space characters. For simplicity, punctuation marks are processed like normal letters. For example, if "I am a student." Is input, "student. A am I" is output ".

The solution is to first flip the entire sentence and then flip each word.

The Code is as follows:

 

# Include <iostream> using namespace STD; void myreverse (char *, char *); char * senreverse (char *); int main () {char Sen [] = "hello, I am a student! "; Char * result = senreverse (SEN); cout <result <Endl; return 0;} void myreverse (char * Start, char * End) {char temp; while (start <End) {temp = * start; * Start = * end; * end = temp; Start ++; end -- ;}} char * senreverse (char * Sen) {char * Start = Sen, * end = Sen + strlen (SEN)-1; myreverse (START, end); // first reverse the entire sentence
/* This annotation is another implementation, but it seems complicated to use int LOC; // record the length of each word for (START = Sen, end = start; (* End )! = '\ 0'; Start + = LOC) {loc = 0; while (* End )! = ''& (* End )! = '\ 0') {end ++, Loc ++;} end --; myreverse (START, end); End ++ = 2; loc ++ ;} */end = start; while (* start! = '\ 0') {If (* end = ''| * end =' \ 0') {myreverse (START, -- end ); if (* end = '\ 0') break; end + = 2; Start = end;} else ++ end;} return Sen ;}

 

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.