#13151: C++簡易參考解答


shawn2000100 (東華財金)

學校 : 國立東華大學
編號 : 57300
來源 : [27.53.168.5]
最後登入時間 :
2021-09-19 19:53:19
d492. 10226 - Hardwood species -- UVa10226 | From: [59.115.2.119] | 發表日期 : 2017-12-19 15:58

#include <iostream>
#include <iomanip>
#include <map>
using namespace std;

int main() {
int T;
while ( cin >> T ) {
getchar();
getchar();

for ( int i = 0; i < T ; ++i ) {
map <string, int> numSpecies;
int total = 0;
string input;

while ( getline ( cin, input ) && input != "" )
++numSpecies[input], ++total;

for ( auto it = numSpecies.begin(); it != numSpecies.end(); ++it )
cout << it->first << " " << fixed << setprecision(4) << (double) it->second / total * 100 << endl;
cout << endl;
}
}
return 0;
}

 
ZeroJudge Forum