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