#include <iostream>
#include<string>
#include<algorithm>
#include<iomanip>
using namespace std;
int main()
{
double n;
while (cin >> n) {
string s, space;
cin.ignore();
getline(cin, space);
if (space == "") {
}
for (int i = 0; i < n; i++) {
string arr[10000];
double arr2[10000]{};
int t = 0;
for (int j = 0;; j++) {
getline(cin, s);
if (s == "") {
break;
}
arr[j] = s;
t = j;
}
sort(arr, arr + t + 1);
float counter = 1.0;
for (int k = 0; k <= t; k++) {
if (arr[k] == "0" || arr[k] == "") {
continue;
}
else {
for (int l = k + 1; l <= t; l++) {
if (arr[k] == arr[l]) {
arr[l] = "0";
counter++;
}
}
arr2[k] = counter;
counter = 1.0;
}
}
double sum = t + 1;
for (int k = 0; k <= t; k++) {
if (arr[k] != "0") {
cout << arr[k] << " " << fixed << setprecision(4) << arr2[k] / sum * 100 << endl;
}
}
cout << endl;
}
}
}
如果把我的arr[10000]改成arr[1000000]就堆疊但我也不知道是哪堆疊。。。
1.
string arr[10000];
double arr2[10000]{};
2.
if (arr[k] == arr[l]) {
arr[l] = "0";
counter++;
}