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 }