Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <bits/stdc++.h>
- using namespace std;
- int reverse(int n) {
- int rev=0;
- while(n>0) {
- int rem = n%10;
- rev = rev*10 + rem;
- n/=10;
- }
- return rev;
- }
- bool palin(string s) {
- int n = stoi(s);
- int a = reverse(n);
- if(a==n) {
- return true;
- }
- return false;
- }
- int main() {
- int t;
- cin>>t;
- while(t--) {
- string s;
- int n,k;
- int count=0;
- cin>>n>>k;
- cin>>s;
- if(palin(s) && k==0) {
- cout<<"Yes"<<endl;
- }
- else {
- for(int i=0;i<(n/2);i++) {
- if(s[i]==s[n-i-1]) {
- continue;
- }
- else {
- s[i]=s[n-i-1];
- count++;
- }
- }
- if(count==k) {
- cout<<"Yes"<<endl;
- }
- else {
- cout<<"No"<<endl;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment