sicily 1323. Switch text

#include <iostream>
#include <string>
#include <algorithm>
#include <sstream>

using namespace std;

bool checkEmptyLine(string str)
{
	for (int i = 0; i < str.size(); i++)
	{
		if (str[i] != ' ')
			return true;
	}
	return false;
}

int main()
{
	string firstStr;
	string secondStr;

	while (getline(cin, firstStr) && getline(cin, secondStr))
	{
		if (secondStr != "" && checkEmptyLine(secondStr))
		{
			reverse(secondStr.begin(), secondStr.end());
			int middleIndex = secondStr.size() / 2;
	
			string tempFirst;
			tempFirst.assign(secondStr.begin(), secondStr.begin() + middleIndex);
			string tempSecond;
			tempSecond.assign(secondStr.begin() + middleIndex, secondStr.end());

			secondStr = tempSecond + tempFirst;

			cout << secondStr << endl;
		}

		if (firstStr != "" && checkEmptyLine(firstStr))
		{
			reverse(firstStr.begin(), firstStr.end());
			int middleIndex = firstStr.size() / 2;
	
			string tempFirst;
			tempFirst.assign(firstStr.begin(), firstStr.begin() + middleIndex);
			string tempSecond;
			tempSecond.assign(firstStr.begin() + middleIndex, firstStr.end());

			firstStr = tempSecond + tempFirst;

			cout << firstStr << endl;
		}

		firstStr.clear();
		secondStr.clear();
	}
	return 0;

}

原来是这样检测空行.....



你可能感兴趣的:(String,include)