Sicily 1323. Switch text

题目地址:1323. Switch text

思路:

      题目意思不好理解呀。

     题目意思是这样的:输入两个测试数据,首先,两个测试数据本身得各自前后倒转,然后两个测试数据倒转后的结果再各自对半互换,然后测试数据二先输出,测试数据一再输出,不断循环下去。还有一点很关键,就是对空行的判断,这个空行可以是空格组成,或者是直接回车,空行是忽略不输出的。

     还是直接看代码吧,这样好理解一点。用stl会使程序简化明了很多,具体如下:

 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 }
原文地址:https://www.cnblogs.com/winray/p/4097533.html