Hustlingbeast_Anish

Palindrome 3

Feb 14th, 2022
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #include <algorithm>
  3. #define lli long long int
  4. #define li long int
  5. #define mod 1000000007
  6. #define ld long double
  7. #define pb push_back
  8. using namespace std;
  9.  
  10. int main(){
  11.     ios_base::sync_with_stdio(false);
  12.     cin.tie(NULL);
  13.  
  14.     int n;
  15.     cin>>n;
  16.        
  17.     string s;
  18.     cin>>s;
  19.  
  20.     string k=s;
  21.     reverse(k.begin(),k.end());
  22.  
  23.  
  24.  
  25.  
  26.     set<char> stt;
  27.     for (int i = 0; i < s.size(); i++)
  28.     {
  29.         stt.insert(s[i]);
  30.     }
  31.  
  32.  
  33.     int h=(s.size())/(stt.size());
  34.     if(k==s || h%2==0){
  35.         cout<<0<<endl;
  36.         return 0;
  37.     }
  38.     lli p=stt.size();
  39.  
  40.     map<char,int> m;
  41.  
  42.     lli ct=0;
  43.     for (lli i = 0; i < s.size(); i++)
  44.     {
  45.         m[s[i]]=m[s[i]]+1;
  46.     }
  47.    
  48.     for (auto it=m.begin();it!=m.end();it++)
  49.     {
  50.         if( (*it).second % 2==0 ){
  51.             continue;
  52.         }
  53.         if( (*it).second % 2!=0){
  54.             ct++;
  55.         }
  56.     }
  57.     // if(p%2!=0){
  58.     // cout<<ct-1<<endl;
  59.     // }
  60.     // else{  
  61.         cout<<ct-1<<endl;
  62.     // }
  63. return 0;
  64. }
  65.  
Advertisement
Add Comment
Please, Sign In to add comment