Sreekar_0125

Untitled

Feb 4th, 2022
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int reverse(int n) {
  6.     int rev=0;
  7.     while(n>0) {
  8.         int rem = n%10;
  9.          rev = rev*10 + rem;
  10.         n/=10;
  11.  
  12.     }
  13.     return rev;
  14. }
  15.  
  16. bool palin(string s) {
  17.     int n = stoi(s);
  18.     int a = reverse(n);
  19.     if(a==n) {
  20.         return true;
  21.     }
  22.     return false;
  23.  
  24.  
  25. }
  26.  
  27. int main() {
  28.     int t;
  29.     cin>>t;
  30.     while(t--) {
  31.         string s;
  32.         int n,k;
  33.         int count=0;
  34.         cin>>n>>k;
  35.         cin>>s;
  36.  
  37.         if(palin(s) && k==0) {
  38.             cout<<"Yes"<<endl;
  39.  
  40.         }
  41.         else {
  42.        
  43.        
  44.         for(int i=0;i<(n/2);i++) {
  45.             if(s[i]==s[n-i-1]) {
  46.                 continue;
  47.             }
  48.             else {
  49.                 s[i]=s[n-i-1];
  50.                 count++;
  51.             }
  52.         }
  53.        
  54.        
  55.       if(count==k) {
  56.           cout<<"Yes"<<endl;
  57.       }
  58.       else {
  59.           cout<<"No"<<endl;
  60.       }
  61.         }
  62.     }
  63.     return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment