Language : C
(NOTE : Try a few times yourself before moving to the solution)
#include <stdio.h>
#include <stdbool.h>
#include <malloc.h>
int Minimum_Operations (int n, char* s) {
int alpha[26] = {0};
for(int i = 0; i < n; i++)
{
alpha[s[i] - 97]++;
}
int sum = 0;
for(int i = 0; i < 26; i++)
{
alpha[i]/=2;
sum+=alpha[i];
}
return sum;
}
int main() {
int T;
scanf("%d", &T);
for(int t_i = 0; t_i < T; t_i++)
{
int n;
scanf("%d", &n);
char* s = (char*)malloc((n+1) * sizeof(char));
scanf("\n%[^\n]s", s);
int out_ = Minimum_Operations(n, s);
printf("%d", out_);
printf("\n");
}
}
No comments:
Post a Comment