include <stdio.h>
#include <string.h>
void ECC(char *a, char *b) {
char temp[50];
strcpy(temp, a);
strcpy(a, b);
strcpy(b, temp);
}
void ECD(double *a, double *b) {
double temp = *a;
*a = *b;
*b = temp;
}
int main(void) {
int N;
scanf("%d\n\n", &N);
while (N--) {
int i;
int L = 0;
double Tc[200000];
char Temp[200000][31];
char Base[31];
while (fgets(Base, 50, stdin)) {
if (Base[0] != '\n') {
Base[strcspn(Base, "\n")] = 0;
int k;
for (k = 0; k < L; k++) {
if (strcmp(Base, Temp[k]) == 0) {
Tc[k]++;
break;
}
}
if (k == L) {
int Sort = L;
Tc[L] = 1;
strcpy(Temp[L++], Base);
for (i = L - 1; i >= 0; i--) {
if (strcmp(Temp[Sort], Temp[i]) < 0) {
ECC(Temp[Sort], Temp[i]);
ECD(&Tc[Sort], &Tc[i]);
Sort = i;
}
}
}
} else
break;
}
double AT = 0;
for (i = 0; i < L; i++) {
AT += Tc[i];
}
for (i = 0; i < L; i++) {
double per = Tc[i] / AT * 100;
printf("%s %.4lf\n", Temp[i], per);
}
if (N != 0)
printf("\n");
}
}
不知道是哪個部分導致會TLE的