Speak the opposite language (c ++ implementation) and speak the opposite Language

Source: Internet
Author: User

Speak the opposite language (c ++ implementation) and speak the opposite Language

Description: given an English sentence, you must write a program to output all words in the sentence in reverse order.

Input: The test input contains a test case that contains a string of no more than 80 characters in a row. A string consists of several words and spaces. A word is a string consisting of uppercase and lowercase letters. Words are separated by one space, enter no extra spaces at the end of the sentence.

Output: the output of each test case occupies one line, and the inverted sentence is output.

Inout: Hello World Here I Come

Output: Come I Here World Hello

You must be familiar with the functions in string.

1 # include <iostream> 2 # include <string> 3 using namespace std; 4 5 int main () 6 {7 string a, B, c; 8 getline (cin, a); 9 for (int I = 0; I <. size (); I ++) 10 {11 if (a [I] = '') 12 {13 c. push_back (''); 14 B. insert (0, c); // string insert function 15 c. erase (0); // delete function 16 continue; 17} 18 c. push_back (a [I]); 19} 20 c. push_back (''); 21 B. insert (0, c); 22 B. erase (B. size ()-1); 23 cout <B <endl; 24 system ("pause"); 25 return 0; 26}


Related Article

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.