sicily 1323. Switch text

本文介绍了如何通过C++实现检查空行的功能,并演示了如何根据特定条件对字符串进行反转操作,包括对输入行的处理及输出修改后的字符串。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#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;

}

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



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值