將所有物種的數量記下來算比例即可。
C++(0.680)
/*******************************************************/
/* UVa 10226 Hardwood Species */
/* Author: Maplewing [at] knightzone.studio */
/* Version: 2016/07/30 */
/*******************************************************/
#include <iostream>
#include <cstdio>
#include <map>
using namespace std;
int main(){
int numTestcase;
while( scanf("%d", &numTestcase) != EOF ){
getchar(); // for '\n'
string input;
getline(cin, input); // for blank line
for( int testcase = 0 ; testcase < numTestcase ; ++testcase ){
if( testcase > 0 ){
printf("\n");
}
map<string, int> numSpecies;
int total = 0;
while( getline(cin, input) && input != "" ){
++numSpecies[input];
++total;
}
for( map<string, int>::iterator it = numSpecies.begin();
it != numSpecies.end() ; ++it ){
printf("%s %.4f\n", it->first.c_str(), (double)it->second / total * 100);
}
}
}
return 0;
}