Gym 100187L - Ministry of Truth

Andrey在真理部工作,任务是修改报纸和杂志上的文章,使其赞美党与BigBrother。最近BigBrother提出将所有单词从右到左和从左到右都读得一样,以简化阅读。Andrey需要在一秒内修改一个字母,使得文章成为回文串。此任务要求快速找到合适的替换方案。

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

Andrey works in the Ministry of Truth. His work is changing articles innewspapers and magazines so that they praise the Party and Big Brother.

Recently Big Brother decided that it would be fine if all words in allarticles are read equally both from right to left and from left to right. Inhis opinion it will greatly simplify the reading of articles — even if the word is read in the reverse order, itssense won't change.

Andrey spends one second to erase one letter from the word and writeanother one to its place. Only one word left to be changed, after that he willcomplete the plan and be able to go home. Of course, he wants to do it as soonas possible. But the truth is that he does not clearly understand right nowwhich word he should get after the replacement. Help him to find it out.

Input

Input contains a single line with the word that Andrey has to change.The word consists of lowercase Latin letters and its length is from 1 to 200000,inclusively.

Output

Output the word which should be a result of Andrey's work. If there areseveral possible such words, output any of them.

Sample test(s)

input

abccabd

output

abacaba

input

wasitadogoracatiate

output

wasitacaroracatisaw

 

思路:

把字符串改为回文字符串,改任意一边即可


代码:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

const int N = 200005;

char st1[N], st2[N];

int main()
{
	while (scanf("%s", st1) != EOF)
	{
		memset(st2, 0, sizeof(st2));
		int len = strlen(st1);

		int i, j;
		for (i = 0, j = len - 1; i<len; i++, j--)
		{
			st2[i] = st1[j];
		}

		for (i = 0; i<len / 2; i++)
			if (st1[i] != st2[i])
				st1[i] = st2[i];

		printf("%s\n", st1);
	}

	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值