Sreekar_0125

Untitled

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