Sicily 1323. Switch text, sicily1323

Source: Internet
Author: User

Sicily 1323. Switch text, sicily1323

Address: 1323. Switch text

Ideas:

The question cannot be understood.

The question is: input two test data. First, the two test data must be reversed before and after each test data is reversed, and then the results of the two test data are exchanged in half, then, test data is output first, and test data is output again and again, which keeps repeating. Another key point is the determination of empty rows. This blank row can be composed of spaces or directly press enter, while empty rows are ignored and not output.

Let's take a look at the code to better understand it. Stl simplifies the program as follows:

 

 1 #include <iostream> 2 #include <string> 3 #include <algorithm> 4 using namespace std; 5  6 bool isempty(string x) { 7     for (int i = 0; i < x.size(); i++) 8         if (x[i] != ' ') 9             return false;10     return true;11 }12 13 void print(string x) {14     if (isempty(x)) return;15     string temp;16     temp.append(x.begin()+x.size()/2, x.end());17     temp.append(x.begin(), x.begin()+x.size()/2);18     cout << temp << endl;19 }20 21 int main() {22     string str1, str2;23     while (getline(cin, str1) && getline(cin, str2)) {24         reverse(str1.begin(), str1.end());25         reverse(str2.begin(), str2.end());26         print(str2);27         print(str1);28     }29     30     return 0;    31 }

 

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.