Saturday, January 27, 2024

[Hackerearth] Palindrome Split

 

Problem Link    : Palindrome Split
Category        : Add Hoc
Contest         : January Circuits '24

#include "bits/stdc++.h"
using namespace std;
#define int     long long int
#define endl    '\n'
 
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    cout.precision(12);
 
    bool FILEIO = true; string FILE = "in.txt";
    if (FILEIO and fopen(FILE.c_str(), "r")) {
        freopen(FILE.c_str(), "r", stdin);
    }
 
    int tc;
    cin >> tc;
    for (int tcase = 1; tcase <= tc; tcase++) {
        string s;
        cin >> s;
        int ans = 0;
        for (char ch = 'a'; ch <= 'z'; ch++) {
            int cnt = count(s.begin(), s.end(), ch);
            ans += cnt / 2;
        }
        cout << ans << endl;
    }
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.