L. Repetitive Palindrome(字符串,回文)

本文探讨了一个字符串问题,即通过复制原字符串n次并连接起来,判断最终字符串是否为回文串。文章提供了算法思路,指出若原字符串本身就是回文串,则无论复制多少次结果都是回文串。

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

传送门

time limit per test

1.0 s

memory limit per test

1024 MB

input

standard input

output

standard output

You are given a string ss consisting of lowercase alphabets, and an integer kk.

Make a new string tt by concatenating kk copies of ss. Determine whether tt is a palindrome, e.g. is the same backward as forward.

Input

The first line contains a string ss consisting of lowercase alphabets. (1≤|s|≤2500001≤|s|≤250000)

The second line contains an integer kk. (1≤k≤10181≤k≤1018)

Output

If tt is a palindrome, print YES. If not, print NO.

Examples

input

Copy

abc
3

output

Copy

NO

input

Copy

abba
1

output

Copy

YES

题解:

题意概括:给你一个字符串str,复制n次与原字符串相加,判断最后生成的字符串是否是回文串。

解题思路:如果原字符串是回文串的话,那么无论复制几次相加都是回文串,反之则一定不是。所以判断原字符串是否是回文串就行了。

//#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

int main()
{
//	freopen("input.txt","r",stdin);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	string str;
	cin>>str;
	ll n;
	cin>>n;
	ll len=str.size();
	bool flag=0;
	for(int i=0;i<len;i++)//注意此处是len,不然会遇到边界问题
	{
		if(str[i]!=str[len-1-i])
		{
			flag=1;
			break;
		}
	}
	if(flag) cout<<"NO";
	else cout<<"YES";
	
	return 0;
 } 

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值