开始想的简单了,确实没想到奇数字母删去一个后也能用
解法:
桶排序
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define endl '\n'
#define int long long
signed main() {
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
vector<int> tong(26, 0);
for (int i = 0; i < s.size(); i++) tong[s[i] - 'a']++;
int flag = 0;
long long sum = 0;
for (int i = 0; i < 26; i++) {
if (tong[i] & 1) {
if (!flag) {
sum += tong[i];
flag = 1;
}
else {
sum += tong[i] - 1;
}
}
else {
sum += tong[i];
}
}
cout << sum << endl;
}
return 0;
}